Selenium Exception with no stack trace (grunt / protractor / selenium) - selenium

I try to run grunt test, and Selenium exits without closing the browser. I am unable to see where the exception is coming from.
grunt test
Running "protractor_webdriver:start" (protractor_webdriver) task
Starting Selenium server
Started Selenium server: http://127.94.0.1:4444
Running "protractor:projecttest" (protractor) task
[10:16:33] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[10:16:33] I/launcher - Running 1 instances of WebDriver
Session created: count=1, browserName=chrome
......Exception thrown: Going to shut down the Selenium server
Shutting down Selenium server: http://127.94.0.1:4444
Shut down Selenium server: http://127.94.0.1:4444 (OKOK)
Fatal error: 10:16:45.529 WARN - Exception thrown
All of my tests are passing. I even added logs to prove the final test passes and exits without exception.
I tried to up my logging from "dots" to "progress" but it doesn't change anything. Any ideas?

Related

Jenkins return job status SUCCESS when the test failed

I am automating my protractor integration tests using Jenkins. When some of the tests fails Jenkins weeps saying that the result was successful. This is my output:
24 specs, 1 failure
Finished in 64.079 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Test failed but keep the grunt process alive.
Done, without errors.[39m
Terminating xvnc.
$ vncserver -kill :28
Killing Xtightvnc process ID 24369
Finished: SUCCESS
I don't know if my problem is selenium or grunt related.
Does any one know what can be the problem? Thanks in advance!
Looks like this Jenkins job is not set up properly, I suggest you review your Job Configuration.
After some research I found out the problem.
I am using "grunt-protractor-runner" library. It has an option call "keepAlive" and it was set to true. This caused the process to continue even is something was wrong and not passing the error code to grunt.
After set it up to false everything behave as expected.

Can I set a longer timeout for protractor to connect to selenium driver?

Running my protractor tests remotely (jenkins) leads to timeout error sometimes. That is not deterministic.
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
[launcher] Process exited with error code 1
/opt/jenkins.dir/workspace/my-jenkins-job/integration-test/ui/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1761
throw error;
^
Error: Timed out waiting for the WebDriver server at http://10.97.193.53:4455/wd/hub
at Error (<anonymous>)
at onResponse (/opt/jenkins.dir/workspace/my-jenkins-job/integration-test/ui/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87:11)
at /opt/jenkins.dir/workspace/my-jenkins-job/integration-test/ui/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:42:21
at /opt/jenkins.dir/workspace/my-jenkins-job/integration-test/ui/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/http/http.js:96:5
at ClientRequest.<anonymous> (/opt/jenkins.dir/workspace/my-jenkins-job/integration-test/ui/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:145:7)
at ClientRequest.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1548:9)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:448:13)
However when I run the tests locally in my mac there is no problem and the tests run perfectly.
I have tried to start the selenium servers manually in the remote machines and I have realised that sometimes it works immediately and sometimes I have to wait up to one minute.
My question is: Is there any way to tell protractor to wait longer for the webdriver to connect?
Environment details
Machine: Red Hat 4.4.7-11
Protractor version: 1.8.0
Selenium Server Standalone: 2.45.0
You can specify it by using driver.wait function.
var webdriver = require('selenium-webdriver');
var protractor = require('protractor');
var driver = new webdriver.Builder().usingServer("seleniumAddress").build();
var browser = protractor.wrapDriver(driver);
browser.driver.wait(driver.getWindowHandle(), 5000, 'Server should start within 5 seconds');
References :
http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait
http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.getWindowHandle
Yes, and it should solve your issue. Use the seleniumServerStartTimeout option in your protractor.conf.js file to bump up the timeout from the default 30 seconds to something longer like 90 seconds:
exports.config = {
seleniumServerStartTimeout: 90000
};
I experienced the same issue on a CentOS 7 VM. For whatever reason the selenium server seems to take wildly different amounts of time to start up each time, and can sometimes exceed the default timeout.

Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser on session null

09:39:51.984 INFO - Got result: Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser on session null
09:39:52.002 INFO - Command request: getNewBrowserSession[*firefox, http://website.localhost] on session null
09:39:52.002 INFO - creating new remote session
09:39:52.003 INFO - Allocated session 4b3951d894ed4a2c94b7fd9758cd5554 for http://website.localhost, launching...
jar:file:/usr/bin/selenium-server-standalone-2.41.0.jar!/customProfileDirCUSTFFCHROME
09:39:52.071 INFO - Preparing Firefox profile...
09:40:12.129 ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: Timed out waiting for profile to be created!
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:307)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.populateCustomProfileDirectory(FirefoxChromeLauncher.java:119)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launch(FirefoxChromeLauncher.java:89)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:346)
at org.openqa.selenium.server.browserlaunchers.FirefoxLauncher.launchRemoteSession(FirefoxLauncher.java:114)
at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:400)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:144)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:105)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:809)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:435)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:405)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:151)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
09:40:12.131 INFO - Got result: Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser on session null
09:40:12.143 INFO - Command request: getNewBrowserSession[*firefox, http://website.localhost] on session null
what i am doing ?
Step 1: Start the hub
The Hub is the central point that will receive all the test request and distribute them the the right nodes.
Open a command prompt and navigate to the directory where you copied the selenium-server-standalone file. Type the following command:
java -jar selenium-server-standalone-2.14.0.jar -role hub
Step 2: Start the nodes
Regardless on whether you want to run a grid with new WebDriver functionality, or a grid with Selenium 1 RC functionality, or both at the same time, you use the same selenium-server-standalone jar file to start the nodes.
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:44444/grid/register (here 44444 is for the environment i am working)
This is due to compatibility issues between selenium and firefox.
You need to upgrade to the latest selenium server, 2.44 at the moment.
Yes! As alec[xe suggested this is due to the compatibility issues between firefox and selenium. For firefox version higher than 30 you must use selenium 2.44 version.Here's the changelog of the selenium please take a look and decide which version of the selenium will fulfill your requirement.
Click here to download the latest(2.44) version of the selenium.

Runtime exception at selenium.start() - Could not start Selenium session: Failed to start new browser session: Error while launching browser

Followed this post -
Selenium - Could not start Selenium session: Failed to start new browser session: Error while launching browser
Error comes up at selenium.start().
I am using selenium rc(2.16) , junit(4.5) in eclipse ide.
The only way to over come this issue is to redeploy our framework in tomcat server, just restart everything.
This is the piece of code that starts selenium
private static HttpCommandProcessor proc;
public static DefaultSelenium selenium;
if (selenium == null) {
proc = new HttpCommandProcessor("localhost", 4444, browserName,
urlName);
selenium = new DefaultSelenium(proc);
**selenium.start();**
selenium.setTimeout(String.valueOf(PAGE_TIMEOUT_TIME));
selenium.useXpathLibrary("javascript-xpath");
selenium.deleteAllVisibleCookies();
}
the selenium server is already started when the execution reaches the above code.
Below is the exception that comes up when execute the tests -
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)
at <package>.SuperClass.connectToUrl(SuperClass.java:340)
Any help or clue to resolve this thing would be appreciated!

Selenium RC throws sessionsid should not be null exception with assertTextPresent, phpunit 3.4 bug only?

I am looking to migrate my selenium RC tests to using PHPUnit 3.4.12 from PHPUnit 3.3.2.
The selenium test will fail with an exception of the following when I use assertTextPresent():
PHPUnit_Framework_Exception: Response from Selenium RC server for getLocation().
ERROR Server Exception: sessionId should not be null; has this session been started yet?.
For example:
public function testSending($browser)
{
...
$browser->click("send");
$browser->waitForPageToLoad("30000");
$browser->assertTextPresent("text");
}
Below is the selenium RC log (running on Windows):
15:40:19.676 INFO - Command request: isTextPresent[text, ] on session 153d03a123c42098711994f43c2db34
15:40:19.691 INFO - Got result: OK,false on session 153d023a123c42098711994f43cdb34
15:40:19.879 INFO - Command request: testComplete[, ] on session 153d023a123c4298711994f43c2db34
15:40:19.879 INFO - Killing Firefox...
15:40:20.269 INFO - Got result: OK on session 153d023a123c42098711994f43c2db34
15:40:20.472 INFO - Command request: getLocation[, ] on session null
15:40:20.472 ERROR - Exception running 'getLocation 'command on session null
java.lang.NullPointerException: sessionId should not be null; has this session been started yet?
As you can see, the test should have completed as indicated by the "Killing Firefox" bit, but it instead continued to do something else and triggered the getLocation[, ] command which caused the exception.
I have tried the same test with PHPUnit 3.3.2 which did not produce this problem - the test would happily end without the getLocation().
Any ideas?
Actually the problem is with setAutoStop() method - by default it's set to TRUE, so PHPUnit sends stop signal to Selenium RC prior to tearDown().
Add $this->setAutoStop(false); to your setUp() method and $this->stop(); to the end of tearDown().