After tons of troubleshooting I finally got selenium to run but it just starts the server and sits on it. Anybody have any idea how to make it run the tests and exit?
[Step 9/9] Executing /home/ubuntu/buildAgent/work/d653d615082dd19f/node_modules/.bin/grunt via wrapping shell script
[16:47:57][Step 9/9] Starting: /home/ubuntu/buildAgent/temp/agentTmp/wrapper3464043714269626324.sh --no-color --teamcity.properties.all=/home/ubuntu/buildAgent/temp/agentTmp/teamcity7605733587545998535.json --teamcity.properties=/home/ubuntu/buildAgent/temp/agentTmp/teamcity414610972945921232.json protractor
[16:47:57][Step 9/9] in directory: /home/ubuntu/buildAgent/work/d653d615082dd19f
[16:48:01][Step 9/9] Running "protractor:myApp" (protractor) task
[16:48:01][Step 9/9] Starting selenium standalone server...
[16:48:01][Step 9/9] [launcher] Running 1 instances of WebDriver
[16:48:02][Step 9/9] Selenium standalone server started at http://172.30.0.51:40590/wd/hub
Selenium is a service, which "starts and runs" :) This is the purpose of Selenium as well as any other service.
If you want to run Protractor tests which runs their own Selenium service, then you should just set Selenium jar and do not set the Selenium address.
export.config = {
// Excerpt of protractor.conf.js
seleniumServerJar: 'node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
// Comment out seleniumAddress
// seleniumAddress: 'http://localhost:4444'
};
FYI People. I had the same use case and I needed the selenium process to close after all the tests were executed.
I wrote a simple power shell script which is what I ended up using later.
# Check if chrome driver is already running.
$java = Get-Process java*
Write-Host $java
if ($java) {
$java | Stop-Process -Force
}
This is obviously not the best script I could write but then it did the job. You can use process Explorer to find that selenium runs on the Java process thread and hence, it is the one you have to kill.
This tiny script is now a part of the build process.
Related
I have a .side file generated by the Selenium IDE, which I need to run on CI using Jenkins.
I am running it as a build step with the following shell command:
selenium-side-runner /path/to/file.ide
The problem arises due to the fact that no matter if the selenium test fails, Jenkins always shows is as success.
In this thread it's suggested to upload the file as generic, but still, the commands to execute it are missing
How to upload a generic file into a Jenkins job?
I've found a possible solution to it on this posts, but I would appreciate having a cleaner way to solve this instead of parsing the results checking for errors.
How to mark a build unstable in Jenkins when running shell scripts
Is there a plugin able to run selenium .side files on Jenkins and this one showing the success/failures of the test?
You can generate a Junit test report file and then use the Jenkins Junit plugin after your tests execution.
selenium-side-runner --output-directory=results --output-format=junit
# Outputs results in `junit` frormat in `./results/projectName.xml'
Check the official documentation for more details.
I am trying to set up automated tests for my web app on Travis CI. I am talking about automated browser tests - running unit tests is simple, but I need a process/system test that will start a headless browser and perform scripted tests of various use cases.
My application is in PHP so I decided to go with PHPUnit, Selenium and headless Firefox.
After a lot of research and trial and error I ended with following .travis.yml file:
language: php
php:
- '7.1'
services:
- mysql
addons:
firefox: latest
env:
- MOZ_HEADLESS=1
DISPLAY=:99.0
SELENIUM_FIREFOX_DRIVER=/home/travis/build/lotcz/zSample/geckodriver
before_install:
- sudo apt-get update > /dev/null
- wget https://selenium/download/url -O selenium-server.jar
- wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux32.tar.gz
- tar -xzf geckodriver-v0.21.0-linux32.tar.gz
install:
- sudo apt-get install apache2
- sudo service apache2 start
- mysql -e 'CREATE DATABASE IF NOT EXISTS zsample;'
before_script:
- nohup java -jar -Dwebdriver.gecko.driver=$SELENIUM_FIREFOX_DRIVER selenium-server.jar &
- composer install
script:
- phpunit --fail-on-risky --fail-on-warning --stop-on-skipped --stop-on-incomplete --verbose --debug --colors
after_failure:
- cat nohup.out
I edited out some pieces specific to my application. Just believe me that I set my application correctly before running the test.
Now a very simple test may look something like this:
class VisitorLoginTest extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp() {
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowserUrl('http://localhost');
$this->setBrowser('firefox');
}
public function tearDown() {
$this->stop();
}
public function testFrontPage() {
$this->url('/');
$content = $this->byClass('main-title')->text();
$this->assertEquals('Hello', $content);
}
}
When my test is run I get this:
The Selenium Server is not active on host localhost at port 4444.
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Skipped: 1.
The command "make test" exited with 0.
Now my problems are these:
this file seems to be really long to me and too complicated given that I want to do something rather standard (I assume that automated browser tests are common these days). I would expect Travis CI to provide an easier way to perform automated browser tests. Here I have to download, install and start Apache, Selenium driver, Selenium server, use composer to get PHPUnit Selenium plugin etc...
Selenium server doesn't seem to be running and I can't find out why.
In the end, because PHPUnit ingeniously return 0 even when it couldn't even run the tests, Travis reports this test as successful. All those flags like --fail-on-risky or --stop-on-skipped still don't force PHPUnit to report a test failure which is in my opinion the only logical result as test clearly failed.
I know this is too broad and contains multiple questions. I am afraid that I took wrong direction somewhere and I am probably trying to do something simple in a complicated way.
Can somebody provide working example of .travis.yml file for automated browser tests? My application is in PHP, but I can write tests in Node.js, Python, Java or anything else as long as tests will really work and failure will be reported if anything goes wrong.
To Execute the above tests, Selenium server should be up and running on localhost with port 4444. Since the server is not up and running on the machine where execution happens try removing below mentioned lines and try.
$this->setHost('localhost');
$this->setPort(4444);
I have problem with running my Selenium tests in Jenkins.
A result of execution is always:
WebDriverException: Message: unknown error: Chrome failed to start:
exited abnormally
My tests are written in Robot Framework and are using Chromium webdriver.
I'm setting needed paths in my command, which looks like this:
export PATH=$PATH:/usr/lib/chromium-browser; export PATH=$PATH:/usr/lib/chromium-browser/chromedriver; . /home/michal/robot_env/bin/activate; robot -L TRACE /home/michal/project_robot/tests
And when I run this command manually in terminal IT WORKS fine (Chromium starts automatically and the test goes on).
So the problem suppose to be in Jenkins. I have installed Xvfb plugin, but it didn't help.
Additionally, in /etc/init.d/jenkins I put these lines:
/usr/bin/X :0 vt7 -ac
export DISPLAY=:0
xhost +
And once again - nothing changed. What else should I set or check?
i got stuck same way.
The problem is that jenkins has it own user, called jenkins, and jenkins user cannot open the browser.
if you try to make "su jenkins" and then "chromium-browser" you obtain the display error.
That because you obtain this issue. The problem is not the webdriver, the problem is the user.
i removed the jenkins user created by jenkins and i createad a normal user called jenkins before installing jenkins.
then i installed jenkins.
now jenkins user can run the test (because it can open the browser) but jenkins itself will not load anymore.
I have recorded some simple selenium tests by Selenium IDE. Now I want to run those tests in Jenkins.
Which plugin to Jenkins do I need to do that? And how to run the tests step by step? Help is appreciated.
you can use recorded selenium IDE script and selenium-server.jar file to run it from Jenkins
Here is steps:
Go to SeleniumHQ page and download Selenium Server file
Eg: selenium-server-standalone-2.33.0.jar
Repair html test suite Use Selenium IDE to record then save as
html test case and test suite then put them in a same folder
eg: TestCase.html, TestSuite.html
In jenkins
Plugin Seleniumhq
Configure Selenium runner file
Manage Jenkins > Configure System > Selenium Remote Control: htmlSuite Runner = path to file u have download in step 1
Configure Job to run
In Build field click " Add build step" then select "seleniumhq htmlSuite Run"
browser: *firefox or *iexploer ....
startURL: http://www.google.com or ...
suiteFile: Input absolutely path to TestSuite.html file saved in step 2
resultFile: Input absolutely path to a file that results will be saved
Hope this help!
I did the same but the following error occurred:
Unable to find the HTML runner. This is normally because you have not downloaded
or made available the 'selenium-leg-rc' jar on the CLASSPATH. Your test will
not be run.
Download the Selenium HTML Runner from http://www.seleniumhq.org/download/ and
use that in place of the selenium-server-standalone.jar for the simplest way of
running your HTML suite.
we are using Jenkins as CI in our project. We were running the CI from the command line using the following command
java -jar C:\\jenkins\\jenkins.war --httpPort=8085 --ajp13Port=8009
As the system needs to restart frequently, we change CI to start as a windows service.
Now we are facing the issues for Selenium test cases. Selenium test cases are not running after we make Jenkins as service. We are getting the following log and no more progress from that point
18:36:30,718 INFO [org.openqa.selenium.server.SeleniumDriverResourceHandler] Command request: getNewBrowserSession[*iexploreproxy, http://192.168.132.105:8080/, ] on session null
18:36:30,718 INFO [org.openqa.selenium.server.BrowserSessionFactory] creating new remote session
18:36:30,796 INFO [org.openqa.selenium.server.BrowserSessionFactory] Allocated session 80b95d0273ac4ea4a82860c79438f071 for http://192.168.132.105:8080/, launching...
18:36:30,796 INFO [org.openqa.selenium.server.browserlaunchers.WindowsProxyManager] Modifying registry settings...
18:36:31,781 INFO [org.openqa.selenium.server.browserlaunchers.InternetExplorerCustomProxyLauncher] Launching Internet Explorer...
Per hudson wiki, you should be running Hudson (or jenkins) as tasks rather than service for GUI testing. Check here. Look at the section GUI Testing in Windows
Following changes will resolve the problem
Update the selenium version.
Use *iexploreproxy or *piiexplore for IE instead of *iehta/*iexplore