In Rails 5.2 with Capybara, it deosn't seem like my assets are being loaded











up vote
0
down vote

favorite












I am attempting to run integration tests on Rails using RSpec Capybara and selenium-chrome driver.



I am also using the capybara-angular gem.



I'm a little confused about exactly whats going on as I don't see my scripts when I sleep my rspec test inspect the the sources tab in the chrome debugger it doesn't seem like my assets are loaded, although it does appear that the ng-if statements are working as the page is hidden.



So I'm not quite sure what's going on. The page works as expected in development, but variables on the $scope are not set in test.



This my set up in "system.rb



   RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome
end
end

require "capybara-screenshot/rspec"
include Capybara::Angular::DSL


Here is the test I am running:



it "shows changes to the budget when the budget is changed", :js do
visit(root_path)
sleep 0.5
fill_in "inputEmail", with: "test@tester.com"
fill_in "password", with: "test"
click_on("Log In")
sleep 0.25
click_on("Budgeting")

sleep 10
expect(page).to have_selector("#current_project_name", text: "Project A")
expect(page).to have_selector("#budgetInput1")

fill_in "#budgetInput1", with: "100"
# Fail on next line with 'expected to find visible css "#budgetInput1" but there were no matches'
page.should have_selector("#budgetInput1", text: "100") # <--test fails with
end


From what I can tell, the reason it is not found is because the element appears in a div with ng-if="showBudget". $scope.showBudget=true is set in the controller, but the controller doesn't appear to be loading and {{showBudget==unknown}} returns true, which suggests that AngularJS is loading but the scripts loaded by the manifest for the page are not.



How to fix this?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am attempting to run integration tests on Rails using RSpec Capybara and selenium-chrome driver.



    I am also using the capybara-angular gem.



    I'm a little confused about exactly whats going on as I don't see my scripts when I sleep my rspec test inspect the the sources tab in the chrome debugger it doesn't seem like my assets are loaded, although it does appear that the ng-if statements are working as the page is hidden.



    So I'm not quite sure what's going on. The page works as expected in development, but variables on the $scope are not set in test.



    This my set up in "system.rb



       RSpec.configure do |config|
    config.before(:each, type: :system) do
    driven_by :rack_test
    end
    config.before(:each, type: :system, js: true) do
    driven_by :selenium_chrome
    end
    end

    require "capybara-screenshot/rspec"
    include Capybara::Angular::DSL


    Here is the test I am running:



    it "shows changes to the budget when the budget is changed", :js do
    visit(root_path)
    sleep 0.5
    fill_in "inputEmail", with: "test@tester.com"
    fill_in "password", with: "test"
    click_on("Log In")
    sleep 0.25
    click_on("Budgeting")

    sleep 10
    expect(page).to have_selector("#current_project_name", text: "Project A")
    expect(page).to have_selector("#budgetInput1")

    fill_in "#budgetInput1", with: "100"
    # Fail on next line with 'expected to find visible css "#budgetInput1" but there were no matches'
    page.should have_selector("#budgetInput1", text: "100") # <--test fails with
    end


    From what I can tell, the reason it is not found is because the element appears in a div with ng-if="showBudget". $scope.showBudget=true is set in the controller, but the controller doesn't appear to be loading and {{showBudget==unknown}} returns true, which suggests that AngularJS is loading but the scripts loaded by the manifest for the page are not.



    How to fix this?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am attempting to run integration tests on Rails using RSpec Capybara and selenium-chrome driver.



      I am also using the capybara-angular gem.



      I'm a little confused about exactly whats going on as I don't see my scripts when I sleep my rspec test inspect the the sources tab in the chrome debugger it doesn't seem like my assets are loaded, although it does appear that the ng-if statements are working as the page is hidden.



      So I'm not quite sure what's going on. The page works as expected in development, but variables on the $scope are not set in test.



      This my set up in "system.rb



         RSpec.configure do |config|
      config.before(:each, type: :system) do
      driven_by :rack_test
      end
      config.before(:each, type: :system, js: true) do
      driven_by :selenium_chrome
      end
      end

      require "capybara-screenshot/rspec"
      include Capybara::Angular::DSL


      Here is the test I am running:



      it "shows changes to the budget when the budget is changed", :js do
      visit(root_path)
      sleep 0.5
      fill_in "inputEmail", with: "test@tester.com"
      fill_in "password", with: "test"
      click_on("Log In")
      sleep 0.25
      click_on("Budgeting")

      sleep 10
      expect(page).to have_selector("#current_project_name", text: "Project A")
      expect(page).to have_selector("#budgetInput1")

      fill_in "#budgetInput1", with: "100"
      # Fail on next line with 'expected to find visible css "#budgetInput1" but there were no matches'
      page.should have_selector("#budgetInput1", text: "100") # <--test fails with
      end


      From what I can tell, the reason it is not found is because the element appears in a div with ng-if="showBudget". $scope.showBudget=true is set in the controller, but the controller doesn't appear to be loading and {{showBudget==unknown}} returns true, which suggests that AngularJS is loading but the scripts loaded by the manifest for the page are not.



      How to fix this?










      share|improve this question















      I am attempting to run integration tests on Rails using RSpec Capybara and selenium-chrome driver.



      I am also using the capybara-angular gem.



      I'm a little confused about exactly whats going on as I don't see my scripts when I sleep my rspec test inspect the the sources tab in the chrome debugger it doesn't seem like my assets are loaded, although it does appear that the ng-if statements are working as the page is hidden.



      So I'm not quite sure what's going on. The page works as expected in development, but variables on the $scope are not set in test.



      This my set up in "system.rb



         RSpec.configure do |config|
      config.before(:each, type: :system) do
      driven_by :rack_test
      end
      config.before(:each, type: :system, js: true) do
      driven_by :selenium_chrome
      end
      end

      require "capybara-screenshot/rspec"
      include Capybara::Angular::DSL


      Here is the test I am running:



      it "shows changes to the budget when the budget is changed", :js do
      visit(root_path)
      sleep 0.5
      fill_in "inputEmail", with: "test@tester.com"
      fill_in "password", with: "test"
      click_on("Log In")
      sleep 0.25
      click_on("Budgeting")

      sleep 10
      expect(page).to have_selector("#current_project_name", text: "Project A")
      expect(page).to have_selector("#budgetInput1")

      fill_in "#budgetInput1", with: "100"
      # Fail on next line with 'expected to find visible css "#budgetInput1" but there were no matches'
      page.should have_selector("#budgetInput1", text: "100") # <--test fails with
      end


      From what I can tell, the reason it is not found is because the element appears in a div with ng-if="showBudget". $scope.showBudget=true is set in the controller, but the controller doesn't appear to be loading and {{showBudget==unknown}} returns true, which suggests that AngularJS is loading but the scripts loaded by the manifest for the page are not.



      How to fix this?







      angularjs rspec capybara rspec2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 23:19









      georgeawg

      32k104865




      32k104865










      asked Nov 21 at 20:55









      user1023110

      9951623




      9951623
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          It looks like you're not using the correct expectation. Since you're able to call fill_in on the element with id budgetInput1 then expecting (not sure why you're mixing expect and should syntax) with the text option isn't going to work. What you probably want is



          expect(page).to have_field('budgetInput1', with: '100')


          If instead you're expecting the fill_in to trigger an update on the page that replaces the input element with id 'budgetInput1' with a different element, then you probably need to be sending an enter, a tab, or clicking outside the initial element to trigger the change.



          On another note, I'm not sure why you have the sleeps in your test - fill_in will wait for the matching element to exist, so there really should be no need to sleep half a second after calling visit -- For the 10 second sleep (does your app really take 10 seconds to respond???) you could just use the wait option on expect(page).to have_selector("#current_project_name", text: "Project A", wait: 10) instead so that the test continues as soon as the element exists, rather than waiting all 10 seconds if it's not necessary.






          share|improve this answer





















          • Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
            – user1023110
            Nov 22 at 4:07


















          up vote
          0
          down vote













          The problem turned out to be a little different than I thought. When I looked at the sources tab, in development I am used a big list of files including everything in my manifest listed. In the capybara test, all those files including jquery and angular are concatenated into a single file. jquery is at the top, and way down at the bottom, which was about line 40000 were my angular controller files. The problem was that that the file it created were not the based on the latest versions of my javascript assets.



          rake assets:clean
          rake assets:precompile


          This was not normally necessary in development, the changes I make in my js files are picked up immediately, but I guess it is required when running Capybara tests with selenium chrome.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420345%2fin-rails-5-2-with-capybara-it-deosnt-seem-like-my-assets-are-being-loaded%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            It looks like you're not using the correct expectation. Since you're able to call fill_in on the element with id budgetInput1 then expecting (not sure why you're mixing expect and should syntax) with the text option isn't going to work. What you probably want is



            expect(page).to have_field('budgetInput1', with: '100')


            If instead you're expecting the fill_in to trigger an update on the page that replaces the input element with id 'budgetInput1' with a different element, then you probably need to be sending an enter, a tab, or clicking outside the initial element to trigger the change.



            On another note, I'm not sure why you have the sleeps in your test - fill_in will wait for the matching element to exist, so there really should be no need to sleep half a second after calling visit -- For the 10 second sleep (does your app really take 10 seconds to respond???) you could just use the wait option on expect(page).to have_selector("#current_project_name", text: "Project A", wait: 10) instead so that the test continues as soon as the element exists, rather than waiting all 10 seconds if it's not necessary.






            share|improve this answer





















            • Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
              – user1023110
              Nov 22 at 4:07















            up vote
            0
            down vote













            It looks like you're not using the correct expectation. Since you're able to call fill_in on the element with id budgetInput1 then expecting (not sure why you're mixing expect and should syntax) with the text option isn't going to work. What you probably want is



            expect(page).to have_field('budgetInput1', with: '100')


            If instead you're expecting the fill_in to trigger an update on the page that replaces the input element with id 'budgetInput1' with a different element, then you probably need to be sending an enter, a tab, or clicking outside the initial element to trigger the change.



            On another note, I'm not sure why you have the sleeps in your test - fill_in will wait for the matching element to exist, so there really should be no need to sleep half a second after calling visit -- For the 10 second sleep (does your app really take 10 seconds to respond???) you could just use the wait option on expect(page).to have_selector("#current_project_name", text: "Project A", wait: 10) instead so that the test continues as soon as the element exists, rather than waiting all 10 seconds if it's not necessary.






            share|improve this answer





















            • Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
              – user1023110
              Nov 22 at 4:07













            up vote
            0
            down vote










            up vote
            0
            down vote









            It looks like you're not using the correct expectation. Since you're able to call fill_in on the element with id budgetInput1 then expecting (not sure why you're mixing expect and should syntax) with the text option isn't going to work. What you probably want is



            expect(page).to have_field('budgetInput1', with: '100')


            If instead you're expecting the fill_in to trigger an update on the page that replaces the input element with id 'budgetInput1' with a different element, then you probably need to be sending an enter, a tab, or clicking outside the initial element to trigger the change.



            On another note, I'm not sure why you have the sleeps in your test - fill_in will wait for the matching element to exist, so there really should be no need to sleep half a second after calling visit -- For the 10 second sleep (does your app really take 10 seconds to respond???) you could just use the wait option on expect(page).to have_selector("#current_project_name", text: "Project A", wait: 10) instead so that the test continues as soon as the element exists, rather than waiting all 10 seconds if it's not necessary.






            share|improve this answer












            It looks like you're not using the correct expectation. Since you're able to call fill_in on the element with id budgetInput1 then expecting (not sure why you're mixing expect and should syntax) with the text option isn't going to work. What you probably want is



            expect(page).to have_field('budgetInput1', with: '100')


            If instead you're expecting the fill_in to trigger an update on the page that replaces the input element with id 'budgetInput1' with a different element, then you probably need to be sending an enter, a tab, or clicking outside the initial element to trigger the change.



            On another note, I'm not sure why you have the sleeps in your test - fill_in will wait for the matching element to exist, so there really should be no need to sleep half a second after calling visit -- For the 10 second sleep (does your app really take 10 seconds to respond???) you could just use the wait option on expect(page).to have_selector("#current_project_name", text: "Project A", wait: 10) instead so that the test continues as soon as the element exists, rather than waiting all 10 seconds if it's not necessary.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 0:29









            Thomas Walpole

            29.3k32546




            29.3k32546












            • Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
              – user1023110
              Nov 22 at 4:07


















            • Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
              – user1023110
              Nov 22 at 4:07
















            Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
            – user1023110
            Nov 22 at 4:07




            Thanks. The sleeps were just to be able to look at the page, and also an experiment to see if the adding a delay would help in case the tests were running before the angular code was finished loading. Not sure why the fill_in worked and the have_selector failed, maybe because the field was existed but not visible? In any event it all works ok now.
            – user1023110
            Nov 22 at 4:07












            up vote
            0
            down vote













            The problem turned out to be a little different than I thought. When I looked at the sources tab, in development I am used a big list of files including everything in my manifest listed. In the capybara test, all those files including jquery and angular are concatenated into a single file. jquery is at the top, and way down at the bottom, which was about line 40000 were my angular controller files. The problem was that that the file it created were not the based on the latest versions of my javascript assets.



            rake assets:clean
            rake assets:precompile


            This was not normally necessary in development, the changes I make in my js files are picked up immediately, but I guess it is required when running Capybara tests with selenium chrome.






            share|improve this answer

























              up vote
              0
              down vote













              The problem turned out to be a little different than I thought. When I looked at the sources tab, in development I am used a big list of files including everything in my manifest listed. In the capybara test, all those files including jquery and angular are concatenated into a single file. jquery is at the top, and way down at the bottom, which was about line 40000 were my angular controller files. The problem was that that the file it created were not the based on the latest versions of my javascript assets.



              rake assets:clean
              rake assets:precompile


              This was not normally necessary in development, the changes I make in my js files are picked up immediately, but I guess it is required when running Capybara tests with selenium chrome.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                The problem turned out to be a little different than I thought. When I looked at the sources tab, in development I am used a big list of files including everything in my manifest listed. In the capybara test, all those files including jquery and angular are concatenated into a single file. jquery is at the top, and way down at the bottom, which was about line 40000 were my angular controller files. The problem was that that the file it created were not the based on the latest versions of my javascript assets.



                rake assets:clean
                rake assets:precompile


                This was not normally necessary in development, the changes I make in my js files are picked up immediately, but I guess it is required when running Capybara tests with selenium chrome.






                share|improve this answer












                The problem turned out to be a little different than I thought. When I looked at the sources tab, in development I am used a big list of files including everything in my manifest listed. In the capybara test, all those files including jquery and angular are concatenated into a single file. jquery is at the top, and way down at the bottom, which was about line 40000 were my angular controller files. The problem was that that the file it created were not the based on the latest versions of my javascript assets.



                rake assets:clean
                rake assets:precompile


                This was not normally necessary in development, the changes I make in my js files are picked up immediately, but I guess it is required when running Capybara tests with selenium chrome.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 4:02









                user1023110

                9951623




                9951623






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420345%2fin-rails-5-2-with-capybara-it-deosnt-seem-like-my-assets-are-being-loaded%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    Alexandru Averescu

                    Trompette piccolo