Running selenium automation tests on remote teamcity build agent - java

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

Related

Android testing on multiplie devices from Jenkins

I'm running Espresso test to test my application. The app have a first time login that requires a code from a text message.
The easiest way to get past the the first time login is to keep the same application installed so that the user data remains.
running the command:
./gradlew connectedAndroidTest
seem to remove the application when the tests are done. Is there any simple way to skip the uninstallation part and just run the tests on all connected devices?
Thank you.
It is strongly recommended that you not rely on state being already setup on the device, but instead, setup the state you need within the test itself.
That being said, you can install the app with gradle and the run the tests with adb.
This assumes a standard default app layout and setup, using androidx.test with a recent version of the android gradle plugin.
First install the app and the tests.
./gradlew installDebug installDebugAndroidTest
Then you can execute the tests:
adb shell am instrument -w com.your.applicationId.test/androidx.test.runner.AndroidJUnitRunner
This will run your app and keep your app and tests installed.
You can run the adb command multiple times in a row and it will execute the tests without rebuilding and reinstalling your app.
Of course, if you make any changes to the app or tests you will need to re-run gradle.
More info:
Installing adb
Running tests with adb
androidx.test
Customize your test run

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

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.

Program to trigger "Build Now" on jenkins and display console output

I have an application that takes the changes and pushes on git. Now i want to create a deploy button on my application, clicking on which, will automatically trigger "Build Now" on Jenkins and display the console output on my application. (I am already storing the userid and password for jenkins within my application.) This will enable me to do everything within my application, from creating the changes, pushing to git and finally deploying it on jenkins and seeing the console output without actually going to jenkins and doing it manually.
More info:My application is built in Spring boot and thymeleaf as frontend.
Thanks in advance.
You can use Jenkins CLI
The command line interface can be accessed over SSH or with the Jenkins CLI client, a .jar file distributed with Jenkins.
with build command
One of the most common and useful CLI commands is build, which allows the user to trigger any job or Pipeline for which they have permission.
Jenkins also has a REST api that you can use, use POsT to trigger and GET for the reults
https://wiki.jenkins.io/plugins/servlet/mobile?contentId=753720#content/view/753720

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.

Launch selenium webdriver test from terminal in linux

I wrote a simple regression test for a website with a little GUI to launch the test. Works fine in eclipse but for some reason it will stall after pressing the launch button on the GUI when I try to run it from the terminal. The web driver will launch firefox but the page stays blank when its supposed to go to the URL of the site I'm testing. I believe this has to do with error in configuring the classpath, I have the following in a shell script
javac -classpath ":ojdbc6.jar:selenium-server-2.33.0.jar:selenium-server-standalone-2.33.0.jar" Test.java
java -classpath ":ojdbc6.jar:selenium-server-2.33.0.jar:selenium-server-standalone-2.33.0.jar" Test
Why does it stall and how to fix it?
I use the Junit ant task to run my tests. It will run my tests and print a nice looking html report at the other end for clear results.
Use Ant or Maven build tool with Junit or TestNG framework as both framework has capability of running test from terminal and generating nice html formated report. Here is a sample project with ant build script you can get from my github account.

Categories

Resources