selenium grid with cucumber - ruby

I am trying to setup selenium grid to achieve parallel execution of my tests. First, I'll explain the my current scenario.
I have my fully functional test suite written in cucumber with watir webdriver
I need to execute all my tests in multiple environments.
I created a setup for selenium hub and node
I can run my tests on a single node through hub
My goal is to run my tests on multiple vm's simultaneously.
I missing a part where I need to configure my tests to run in parallel. there are some examples about grid setup in the web, as I am using different framework I couldn't relate to my scenario.
Thanks in advance

I was able to do this by leveraging Jenkins with Selenium Grid... Why Jenkins? a) Jenkins is a build tool and is built to run parallel jobs by default. I leverage that ability to send tests to Selenium Grid in parallel, the Grid manages the flow from that point on. b) Jenkins is part of many development build processes. Dev's could make calls to your QA jenkins to kick off tests as they commit/build. c) Jenkins provides a nice UI to see pass/failures of your tests (as well as sending email notifications of failures) and d) Jenkins has a great Cucumber reporting plugin.
You could avoid Jenkins, but you'll need to send your cucumber features in parallel to the Grid. If you just run cucumber, it will farm jobs to the grid, but they will run sequentially. You would need something to kick off each feature async.
Below is my full set up. Jenkins is basically being used here to start multiple/simultaneous cucumber jobs. the details are below:
Grid Setup
I had 10 VM's. I took VM1 as my primary. It was a windows server box, so I put the selenium grid standalone on it and wrote a batch file like so:
#echo off
“C:\[Add your Java Path Here]\java.exe” -jar “C:\[Add your Selenium Grid Jar Path]\selenium-server-standalone-2.31.0.jar” -role hub
Then used the windows server task to auto run that batch file in case of VM restart.
On each of the other VM's I made them part of the grid by registering them with VM1 (hub):
java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://[the server name of your Selenium Hub]:4444/grid/register -browser browserName=chrome,maxInstances=5
Cucumber Set UP
In Cucumber, I set up a env.rb file in the features/support folder. This allows me to specify command line arguments before the tests run, and what happens when they stop. I added a begin statement that set the a value for using a browser, as well as using the Grid...
Browser & Environment Config
In the env.rb file I add:
def browser_name
(ENV['BROWSER'] ||= ‘firefox’).downcase.to_sym
end
def environment
(ENV['ENVI'] ||= ‘int’).downcase.to_sym
end
Grid Config
Then I add:
Before do |scenario|
p "Starting #{scenario}"
if environment == :int
#browser = Watir::Browser.new(:remote, :url=>"http://[Your Selenium Grid Hub]:4444/wd/hub", :desired_capabilities=> browser_name)
#Optional: in the case of setting your default start page #browser.goto "http://[your start page of your test site]:8080"
elsif environment == :local
#browser = Watir::Browser.new browser_name
#browser.goto "http://[some other environment]:8080"
end
end
Now you could pass a argument like: cucumber feature/login.feature BROWSER=firefox ENV=int and it would farm all the work to the Grid HUB - which should pass it to the Grid NODES it's connected to, with the browser support (i.e send the test for login.feature to a firefox compatible node - maybe not all your nodes have firefox, if they all do, then it will go to any one of them.)
At this point, you get one job at a time going through. So how to run more then one?
You would have a script that kicks off all feature files (or sans-Cucumber, your tests) through that same browser profile to use the Grid HUB. If you use a script it needs to make these calls asynchronously - so all the features/tests are sent to the Grid at the same time and the Grid manages the jobs.
How I did that was with...
Jenkins
Jenkins is used for builds/deploys of code - but in my case I use it to trigger QA jobs. Jenkins is a Java JAR, that you just run... i.e. java jenkins.jar It launches a local UI on some port, and you can start adding jobs.
From a high level
I built Jenkins jobs and had a parent job that ran all jobs - sending them to the Grid. The Selenium Grid Hub would then manage the flow of the jobs.
I wanted to be able to kick off individual feature tests, individual feature tests by browser, and all tests by browser. To do that I started with individual jobs for each feature by browser.
Details
In Jenkins I created "A New Job" and choose "Free style software component" and then filled out the description with "[my feature name] [browser name]" i.e. Login Tests via IE
Down in the Build section of this Jenkins job, I choose to use a BATCH Command. Since it's a windows box, I picked Windows Batch command and input something like this:
bundle exec cucumber BROWSER=ie ENVI=int features/login.feature --format json -o login-results/login.json
That stuff from --format on, that's all making use of a Cucumber reports plugin for Jenkins. It makes these nice looking graph driven reports on the features tests that passed/failed. You don't need it, it's optional.
If you "build" the Jenkins job, it will execute that windows batch file and it does the following:
Starts the Job
Runs a cucumber command to use a specific browser (IE in this case)
Runs all the tests of that feature file (i.e. login.feature could have 20 tests)
All tests run through the grid, which farms them off to nodes
It's not yet running jobs in parallel though.
Running Jobs in Parallel
Now that Jenkins can kick off the tests by feature and browser, via a Grid - we can now finally run jobs in parallel, we just need more jobs. So create a few more jobs... like:
Jenkins job for registration.feature, and jenkins job for subscription.feature. Each will have it's own windows batch command like:
bundle exec cucumber BROWSER=ie ENVI=int features/registration.feature --format json -o registration/registration.json
Or
bundle exec cucumber BROWSER=ff ENVI=int features/registration.feature --format json -o registration/registrationff.json
That last one is a duplicate of the registration test, just calling a different browser.
Jenkins by default limits how many simultaneous jobs you can run.. I think it's 10. You can change that in the Jenkins config. I changed mine to 40.
So now, you can click on your first Jenkins job:
Login Test via IE
and click BUILD
As it starts, click "BUILD" on your second job:
Registration Test via IE
and the same for your other jobs...
Jenkins will start each job in parallel, farming them to the Grid HUB, which sends the jobs to your appropriate nodes! All in parallel. By default Jenkins limits the jobs to 5 or 10 parallel jobs. You can change that. I modified mine to be 25 to 40, depending on my needs.
Jenkins will also update the UI with pass/fail and has details of the failures in the logs of each job. You can see the history of the failures... and another Jenkins repo (i.e. the dev repo) can make rest calls to your repo to auto trigger these test as they build.
Launching All Tests From One Job
Rather then manually running your individual jobs, you can build a parent job. In Jenkins the parent job would be a NEW Job that is the same type, "Free style software component." You go down to the very bottom and it should have a field called, "Build Other Projects" In that field you can put each project for deploying: Login, Registration, etc.
Now when you "Build" this parent job, you'll see Jenkins starts all jobs/Projects to kick off at the same time. Basically your entire set of tests could start with one click - all being sent to Selenium Grid, which would then manage the flow.
Group Tests
In Jenkins I create tabs for my tests... IE Tests, FF Tests, Chrome Tests, etc.
In each tab I put the appropriate features.
Then I create a new Parent job to kick off all jobs of a type like:
All IE Tests
All FF Tests
etc.
Conclusion
You can probably avoid Cucumber if you like. You just need something to kick off the jobs in parallel, for me I used Jenkins to do that. You could use a script that runs async jobs (kicking off your tests.)
Hopefully something in post is useful to your needs.
I have this documented at my site, along with some pictures of the Jenkins flow...
URLs
My tutorial on setting up Cucumber and Selenium Grid:
http://sdet.us/selenium-grid-with-watir-and-cucumber-browser-automation/
My tutorial on setting up Cucumber Reports with Jenkins:
http://sdet.us/jenkins-and-cucumber-reports/

look at MBUnit as this can run tests in parallel, This should help. It will only run tests in parallel in one assembly and will not coordinate across multiple assemblies.

Related

Re-run Cypress test in Github Actions does not work

I have a cypress workflow in Github and it runs nicely. But, when the e2e tests fail for some reason and I want to re-run them using the re-run all jobs button (below), the following message appears:
The run you are attempting to access is already complete and will not accept new groups.
The existing run is: https://dashboard.cypress.io/projects/abcdef/runs
When a run finishes all of its groups, it waits for a configurable set of time before finally completing. You must add more groups during that time period.
The --tag flag you passed was:
The --group flag you passed was: core
What should I change in my configuration to make these possible? Sometimes the e2e fails because of a backend error that is fixed later.
I'd like to do this instead of a force e2e commit.
I was facing the same issue before.
I think you can try to pass GITHUB_TOKEN or add a custom build id. It fixed my issue. Hoep it helps.
https://github.com/cypress-io/github-action#custom-build-id
Check your Cypress Dashboard subscription plan. Mine got the free plan full (500 test for free and I was running in 3 different browsers 57 tests, so it got full pretty quick since this is 171 tests in one run) and after that it didn't allowed me to keep running or re running more parallel tests. Test kept running but in 1 machine out of 4 in the first browser and stages for the other 2 browsers started failing, I was able to allow the pipeline to not be failing by passing continueOnError: true in the configuration.
Quick edit, I don't remember where but I read that you could also add a delay to your pipeline and/or reduce the default wait on the Dashboard which is 60s(https://docs.cypress.io/guides/guides/parallelization#Run-completion-delay)

Pausing Teamcity builds that are running

I would like to have Teamcity build configuration that currently has 3 build steps:
Build an artifact to perform tests on & install on remote server
Kick off long running test job on remote server
Pause build awaiting external event (i.e. remote job finishing)
Retrieve results and record the report
I have had a look through the documentation and I can see how I can pause (step 3) the entire build configuration (which stops any additional builds running) ... but not just a single running build.
The Step 2 script that is running the external job has the various parameters passed to it, so that it can issue a REST call back to the teamcity server to resume the build job.
Basically I don't want to tie up a build agent waiting the entire hour the test takes to run.
I have googled and everything I can find points me at pausing the build configuration.
I am currently having to look at splitting the build configuration into two. The first will kick of the test job and finish. Then when the external test job finishes it will call teamcity to start a second job to retrieve and store the reports. But that feels disconnected to me in that I will not be able to show a single job with build/test/report.
At the moment (TeamCity v 2018.1) there is no direct way to pause the build, release the build agent, and later resume the execution.
What you described is the recommended workaround.
Also, please watch/vote for related issue: https://youtrack.jetbrains.com/issue/TW-30777

How Can I compare output of 2 different JMeter runs automatically?

I want to compare 2 different jmeter runs.
I have a jenkins job to do that which triggers jmx which in turn call Rest APIs.
Lets say, I executed Jmeter run for one time. I will refer this as run 1
Now, after 30 minutes, I will again run the same jenkins job and will again run the jmeter test. I will refer to it as run 2.
So, now i have 2 runs and i want to compare run1 and run2, specifically the response time.
How can I automate that so that everytime this happens, i can have the difference in response time of APIs ?
I tried searching, found few articles (Compare results from a previous test in jmeter) but it did not really help :(
Please let me know how can this be achieved ?
You can use MergeResults plugin in order to compare 2 test executions and plot execution chart and/or have differences in the CSV file.
If you want to run it in non-GUI mode from Jenkins job - go for JMeterPluginsCMD Command Line Tool which has MergeResults plugin to run it in command-line mode.
You can install both the plugins using JMeter Plugins Manager

execute jmeter test plan inside cucumber step in ruby

This must be easy but I am struggling so I post it here. I am new to Jmeter, and I have to use it to send messages. I am testing a messaging portal which uses a core messaging application where the portal gets the data from this application. Now there are clients who connect to this messaging application and when they send messages, the application processes it and the portal application displays it. I am using JMeter right now as a test harness simulating the client interface to send these test messages. My colleage who knows JMeter has created the .jmx file which has all the settings, the url, thread count,format of the message. All I have to do is open the .jmx file in GUI or on command line and send it. It works. I wanted this process of JMeter sending the messages automated in my cucumber step. So that when I write a step like:
'Given when clients sends a message'
then the step definition would be a command or script to execute the JMeter test plan.
I tried doing this by giving the line in my step definition:
system('start jmeter.bat -n -t sample.jmx ')
I am using ruby and the system command is the ruby way to execute external commands, in this case it is a windows command. -n is to run the JMeter in non-GUI mode and -t is to mention the .jmx file. The problem I have here is, anytime I run the JMeter in non-GUI mode, it opens a terminal, executes and the control stays there. So when I use this script in my cucumber steps, the control stays there in terminal and my cucumber scenarios fails.
How can I do this in a different way so that the JMeter test plan gets executed in the background or I get the control back to my cucumber step?
Note: I may have a solution using the ruby-jmeter gem : https://github.com/flood-io/ruby-jmeter but I am not finding a way how to simply execute this using the gem. Here in the gem he tells of running the test plan locally or on flood-io but not at a different url. In my case the url is an IP address where the messaging application is listening and I use JMS publisher in JMeter to send messages via GUI. I created the .jmx file using the GUI and the same can be used in command line successfully. Please let me know of any solutions.

How to solve errors from running jobs in parallel using Jenkins and watir webdriver?

I'm running tests from Jenkins on Windows and tests which work fine when only one is executing at a time encounter errors when multiple jobs are running on separate build threads at the same time. I am using Watir webdriver. The creation of the browser is using the code:
profile = Selenium::WebDriver::Chrome::Profile.new
browser = Watir::Browser.new :chrome, :profile => profile, :http_client=>client
The tests are written in Ruby with Cucumber and I am using tags to run a subset of the tests in each job. The tests are executed with cucumber from the "Execute Windows Batch Command". Opening up two command line instances on my desktop and running the jobs in parallel works fine.
A couple of different errors seem to recurr. One is:
[0412/111507:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends
[0412/111552:ERROR:proxy_launcher.cc(114)] WaitForInitialLoads failed.
[0412/111552:ERROR:proxy_launcher.cc(556)] Failed to ConnectToRunningBrowser
[0412/111552:ERROR:automation_proxy.cc(319)] Channel error in AutomationProxy.
[0412/111552:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends
[0412/111552:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends
Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: C:\Users\steve\AppData\Local\Google\Chrome\Application\chrome.exe (Selenium::WebDriver::Error::UnknownError)
the other is
No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED)
An example run which works via command line on my desktop and not through Jenkins is:
cucumber --tags #event_discounts ENVIRONMENT=beta
and
cucumber --tags #WhiteList ENVIRONMENT=BETA
Any suggestions on how to solve this?
The solution is to open services, open the properties for Jenkins, click on the "Log On" tab and check "Allow service to interact with desktop" then I restarted Jenkins by going to http://localhost:8080/safeRestart
and clicking yes, now tests will run in parallel correctly.
Unfortunately I now get pop-ups about Interactive Services Detection, but I can move that to the corner of the screen and ignore it.

Resources