How setup selenium firefox tests on CodeShip? - ruby-on-rails

Intro
Hi, I'm developing rails application, which use capybara, selenium-webdriver and rspec for tests.
Problem
Now I have a functional tests, which runs in firefox (default selenium browser) and works with redirects to other hosts. For example, rspec before hook to get fresh google access token.
Locally on my laptop all tests runs with success:
bundle exec rspec
But codeship's builds fails.
Questions
Do I need to setup codeship to support "firefox" tests? If yes, how can I do it?
Does codeship supports redirects to other hosts?
Thanks!

Codeship supports running selenium tests in the CI , you can find more info here https://documentation.codeship.com/continuous-integration/browser-testing/
However when i tried to run the selenium tests in CI , chrome failed to start 90% of the times , so i am planning to spin up a selenium grid elsewhere and run the tests in codeship

Related

functional test working in production but not in development

I'm working on a rails website, currently writing some unit, functional and integration tests.
The unit and integration test are running fine in development(my local machine) and production (on gitlab pipeline).
Strange thing is: functional test is failing on my local machine but passing in production pipeline!
I'm using rake to run my tests; rails 4.2 on macOS as my local machine setup, and gitlab is using docker to run the tests
what might be the issue?

Rails system test with capybara and headless selenium browser in Docker

TL;DR: Any idea about how to properly configure capybara to be able to drive a remote selenium browser in a docker container with default Rails minitest system test?
I'm running Rails in a dockerized env..
Now I want to start some "system tests" but since I'm running inside Docker I come up with some issues.
I'm using the default test suite (minitest?) with capybara and selenium-webdriver gems.
I've already installed the chromedriver packet in the container using the following:
RUN apt-get install -y chromedriver \
&& ln -s /usr/lib/chromium-browser/chromedriver /usr/local/bin
But running rails test:system outputs the following error Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver.
In fact I don't know if chrome itself is installed or not?
which chrome outputs nothing.
which chromium outputs /usr/bin/chromium.
I also tried with xvfb without success.
So (since I had no clue) I tried to go further and actually go with a dockerized system test environment as well.
I found some Docker images from selenium. So I ran among my rails and database containers a selenium-standalone-chrome container (the actual docker-compose.yml I'm using is here)
Then I found some useful information about the configuration to be done to let capybara driver the remote selenium browser.
All the examples I found on internet use rspec, but since I'm using the default minispec I tried to adapt the capybara driver to minispec but I had some doubt about how to do it and where to put the configuration.
For system tests I guessed that the best location is the file application_system_test_case.rb. Also I found and I tried many different capybara configurations and I end up with the following which seems to be the most complete (available here)
At that moment the test seems to perform well since I have no error but it always fails.
It fails regardless of making a call to the driver configuration (the setup_remote method where I defined the server host and port) before the tests case.
With or without the call I got the "site can't be reached" error (here is the screenshot)
Here is the test file I used. (Testing some react dynamic display)
However I can access to the selenium container with the given URL from the browser from my host machine. And both containers sees each others. I did some ping from within the containers shell.
The following SO questions being helpful don't work for me:
Dockerized selenium browser cannot access Capybara test url
How can I run headless browser system tests in Rails 5.1?
Any idea about how to properly configure capybara to be able to drive a remote selenium browser in a docker container with default Rails minitest system test?
Thank you very much.
You have to override the host method so Capybara uses the container's IP address. Check out this post: https://medium.com/#pacuna/using-rails-5-1-system-tests-with-docker-a90c52ed0648

Run tests on a project under the same solution running on localhost Selenium

How do I run Selenium tests on the main project if the main and the test project are in the same solution and running on localhost?
You can deploy the mvc website into IIS (local/remote) and use the URL in selenium to invoke your project. e.g. driver.get("http://localhost/website/default.aspx")

Running parallel selenium tests with capybara

Background:
I have a set of Capybara integration tests running against my Rails 3 Application. For the other parts of the test suite I'm using Rspec.
I have a selenium 2.6.0 standalone server hub on my Mac OSX dev machine.
java -jar selenium-server-standalone-2.6.0.jar -role hub
I'm running several virtual machines each hooked up to the hub with a selenium node:
java -jar selenium-server-standalone-2.6.0.jar -role webdriver -hub http://0.0.1.12:4444/grid/register port 5555 -browser browserName="internet explorer",version=8,platform=WINDOWS
This works fine, In this screenshot the console shows that I have an IE7 and an IE8 browser connected to the hub:
I've setup capybara to run against the selenium hub (that delegates the tests to the nodes).
Capybara.app_host = "myapp.dev"
Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:url => "http://localhost:4444/wd/hub",
:desired_capabilities => :internet_explorer)
end
It works, however it will only run the test on a single internet_explorer node. It seems to be the one that is "first in line"; If i turn it off, the test will successfully run on the other node.
I've been trying out the parallel_tests project, configuring capybara as suggested, but that would still only launch one integration test.
How can I run my integration on all internet_explorer nodes simultaneously?
Bonus question: If i wanted to run my integration tests on all connected nodes, regardless of browser capability, how would i do that?
Here you have to fire the same tests for different browser so can try to start two process of tests i.e. Run the same command twice.
As you have started the nodes the Grid will handle the execution on different nodes.
In your case you are executing the test and only on suite/process is started with respect to Grid. Just for testing Purpose try firing these tests twice one after another. If you are not able to Achieve by this Use Ant or similar thing to control your execution of tests.
For IE webdrive you can run at most 1 test on one physical node! If you want to achieve parallelism with IE webdriver than you can try by add/register more physical node to the hub.
Regarding above screen shot of hub console, it also shows you only one IE icon. The message is wrong that "Supports up to 5 ...." but you can consider number of icon for respective browser displayed below it.

Can I run grails integration & functional tests against a running server?

I'm finding the feedback look pretty slow when running integration and functional tests in Grails. Is there a way I can run them against a running server instance while I'm writing the tests, to save on server startup time each time they're executed?
You can use grails interactive which does what you want without starting a server. It starts a JVM and keeps it running and you can use it to run unit and integration tests. Keep in mind that you'll eventually run out of memory and need to restart periodically. See http://docs.grails.org/latest/guide/gettingStarted.html#usingInteractiveMode
Also in 1.3.5 you can run functional tests against a running server. Use the baseUrl attribute described in section 9.3 at http://grails.org/doc/latest/
there's an option --baseUrl
e.g.
grails test-app --baseUrl=http://localhost:8080/myapp/
that runs tests against a running instance, one draw back is that the slate isn't wiped clean after a test, so if your test writes to the db, uploads a file, or some other permanent change to the application, then you may have to do some tearDown.
This is briefly documented at the end of the function testing section of the grails docs
http://grails.org/doc/latest/guide/testing.html#functionalTesting
It's useful for writing/debugging functional tests
I'm using Grails 1.3.5 and the EasyB plugin for stories in the context of functional tests.
Take a look at http://padcom13.blogspot.com/2010/10/grails-easyb-and-selenium.html for step-by-step instructions.

Resources