How do I limit simultaneous Selenium browsers being run by Jenkins? - java

I have a Jenkins project that runs more than a hundred Cucumber feature files. Each test scenario uses Selenium because I need to test the UI of my website. The problem is that Jenkins tries to run them almost all at once hence I get an explosion of Selenium Google Chrome browsers trying to pop up all at once. This leads to my machine running out of memory and only a few Selenium browsers being responsive.
Is there a way for me to limit the number of Selenium browsers being active at one time? It could be on Jenkins or in Selenium but I'd rather stay away from Selenium Grid.
I've already tried looking into limiting it in Jenkins but it seems like you can only just limit the number of parallel builds. My problem is that I only have one build and it's executing all tests almost all at once.
As for Selenium Grid, the command that is used in the build step of Jenkins explicitly says NOT to use Selenium Grid.
Under Jenkins, for the Execute Windows batch command:
cd folderLocation
mvnw clean verify -Dgui.feature.tags=#test -Dbrowser=chrome -Dforked.jvm.count=3 -Duse.selenium.grid=false
With this command, the test runners are created to specify all scenarios to be run and the location of the results JSON files.
The codebase for Selenium, Java, and Maven are copied from another machine. When you run the Jenkins project manually, they have a limit of active Selenium browsers at a time on that machine. However on the new machine, we re-did the setup of Jenkins and if you run the build, it will try to start all the Selenium browsers all at once and most browsers ended up being unresponsive. After a while, it will end up in an error memory dump.
I repeat, is there a way for me to limit the number of Selenium browsers open?

Two solutions:
There is option "Build Trigger"
Build after other projects are built use this.
Or merge all your UI automation into single job if possible, so that, at the time you can have one build.

Related

Selenium-java,TestNG and jenkins on CentOS

I have recently setup integration of Selenium (Java bindings) with TestNG and Jenkins in a Windows environment, which is running absolutely fine.
I have created a batch file of TestNG and executed it through Jenkins using Windows batch file command. Now the situation is that I have to run these Selenium test cases on a Linux (Centos 7) environment as the Jenkins is setup there.
I am not quite sure how I should approach that. I have gone through some articles, but really could not find anything related to this for Selenium/Java things.
I have already done some initial steps, but I'm stuck after that:
I have setup CentOS 7;
Installed Java on it;
Installed Jenkins on it;
I have also installed xvfb as it would be required for headless execution.
From here I need some guidance in terms of how to proceed further, or put all things together. For example, should I move Selenium/Java project on VM and somehow run the TestNG file through Jenkins? (but not sure how to do that need some steps to follow or are there any more prerequisite to it). Or some other approach which is better.
It would be great if someone can guide me towards any article or can explain here with steps.
Here's what you can try doing to get this working:
You need a version control system(VCS) such as GIT/SVN, wherein you would need to push in your test code. That way, your Jenkins Instance will be able to pull in code from the VCS.
Once you have pushed in your code into the VCS, you can create a build job which would pull code from your VCS, build it using a build tool such as Maven/Gradle/Ant and then execute your tests (again using the build tool)
To learn how to setup your Jenkins instance with Git (One of the popular VCS flavors), please refer to this blog.
To learn how to go about setting up a Continuous Integration system with Selenium, you can also refer to this blog post of mine.

automatically run external application, which use Cucumber for testing main application

We have application which use Cucumber framework for testing our second application, the applications runs on own processes (black box testing), currently we do following steps:
1) Run DB
2) Run main application
3) Run test application which use Cukumber framework for testing main application
Question is: how we can do this automatically by using TeamCity ?
Create a Command Line build step:
Point to the working directory
Run your Cucumber tests from the command line. Example.
Here is more info on Cucumber's CLI.
My approach would be to write a script that sets up all dependencies. I.e. starting the database, starting the second application and then run the Cucumber stuff. The script would be possible to run on the CI server, i.e. TeamCity or on a developers system so it is easy verify that they didn't break anything before committing.
Restricting the execution to TeamCity only would not be my preferred approach.
This lead toa solution taht depends on your dev and CI environment. Are you running on Windows or on Linux? The scripts will different depending on the operating system.

How to switch Selenium WebDrivers using Gradle?

I am running some Selenium tests on a Java project using Gradle. I would like to have 2 different Gradle tasks: one to run the tests using the local WebDriver and one to run the tests against a RemoteWebDriver (which will hit a Selenium Grid server). Right now I have a base.properties flag called useRemoteDriver that I can set to true or false to run local or remote tests.
Is there a way I can get a Gradle task to either change this property on execution or is there another way I can accomplish this?
If I understand this right, you want a property which has a default value but you can override when calling gradle in the command line.
I use a similar setup where I declare
env=Dev
In my gradle settings file and have the option of supplying
-Penv=Production
Via the command line to gradle

Running selenium automation tests on remote teamcity build agent

Recently we started using Teamcity for build management and to run selenium junit tests using ANT scripts. The tests are running successfully and shown as passed on teamcity console.
When the tests are running if I login to the build agent machine, I was expecting to be able to see the browser window open and fields getting populated and submitted. I don't see the Firefox browser window open, wondering how my tests are passing. When I run the same test scripts in Eclipse, the Firefox browser window is opened and the web page fields get populated.
Appreciate your comments.
Because TeamCity build agents are run as a Windows service. So you won't be able to see the actual GUI.
If you want to change it, please change your build agent installation.
Installing and Configuring the TeamCity Server
How can I run a Windows GUI application on as a service?
Selenium Tests run in the background when TeamCity CI is run as a Windows service
Running Automated GUI tests with TeamCity

How to open and run a specific script from the command line in eclipse

I am trying to run an automated suite every day at the same time, so I want to create a task to open eclipse and execute the main script every day. Is there a way to do this from the command line?
Instead of using eclipse for it, use a software that is dedicated for it - continous integration servers are created for it. Check such titles like: hudson, cruiseControl, TeamCity
You are on the wrong path. Instead of trying to automate opening eclipse, executing a main... break the IDE dependency, write a portable build script using Ant or Maven and execute that build script outside the IDE (using a simple cron job or something more elaborated like a Continuous Integration tool but I'm not sure you need a CI tool for now, start with the build script).
So I am assuming that you want to automate something that you run from inside eclipse. if it's a build then I'm with the other guys that using a build script and CI is the way to go.
But in case it's not that use case...
Now, if you are using the "Run.." dialogs to do this you can actually get the command line paths, binaries and arguments that eclipse used to execute.
What you do is open up the debug perspective. Then run your script however you normally do.
Your Process should appear in the "Debug View" at this point.
Either while the process is running or after termination, right click on the process and open up the properties. (you may need to click 1 level down in the tree to get this option)
Under process info, inside of that there is a section "Command Line". This is the exact command line that eclipse executed behind the scenes to run.
you should be able to put this into a script (.bat for windows / sh for *nix) and schedule accordingly.
edit: added in assumptions, changed to use process info terms which is what is on the properties screen.

Categories

Resources