Unable to run basic first test case on Linux

426 views
Skip to first unread message

shruthi v v

unread,
May 30, 2016, 6:17:02 AM5/30/16
to seleniu...@googlegroups.com
My code is below

package testng;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.Test;

public class testone
{

@Test
public void newtest()throws InterruptedException
 {
  WebDriver driver=null;
  // Optional, if not specified, WebDriver will search your path for chromedriver.
  System.out.println("First line");
  System.setProperty("webdriver.chrome.driver", "/var/lib/jenkins/jobs/ShruthiTest/workspace/chromedriver");
 // System.out.println("second");

  driver = new ChromeDriver();
  System.out.println("Third");
  driver.get("https://www.facebook.com/");
  System.out.println("fourth");
 }
}


Console output

run:
   [testng] [TestNG] Running:
   [testng]   /var/lib/jenkins/jobs/ShruthiTest/workspace/NewTestNg/testng.xml
   [testng]
   [testng] First line
   [testng] Starting ChromeDriver 2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a) on port 31734
   [testng] Only local connections are allowed.
   [testng] log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
   [testng] log4j:WARN Please initialize the log4j system properly.
   [testng]
   [testng] ===============================================
   [testng] UOLO Test Suite
   [testng] Total tests run: 1, Failures: 1, Skips: 0
   [testng] ===============================================
   [testng]
   [testng] The tests failed.

BUILD SUCCESSFUL
Total time: 1 minute 14 seconds


This is my first test case ,I am trying to run on Linux box and every-time test fails .Please tel me what I am doing wrong here and how to check stack trace ?












Shruthi

Md. Rahman

unread,
May 30, 2016, 6:41:39 AM5/30/16
to seleniu...@googlegroups.com
use
Webdriver Driver = ChromeDriver()

then set the properties for the ChroeDriver and path


Best Regards
Md. Sakibur Rahman



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAERCCeOfDuBCrTAoG%2B2AWcF9Ud19p4bx%3DbeVV_Wd0vkq7q%2BUuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

⇜Krishnan Mahadevan⇝

unread,
May 30, 2016, 6:47:15 AM5/30/16
to Selenium Users
How are you running your tests ? Can you please share the exact maven command line args (options) that you are passing via Jenkins ?

It would be good if you could please help create a testng suite xml file wherein you have bumped up the verbose tag's value to 2 or higher.

See here for some reference.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--

shruthi v v

unread,
May 30, 2016, 7:50:08 AM5/30/16
to seleniu...@googlegroups.com
I have not configured my project with maven and Iam running with command ant clean compile and run 

This is my xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="UOLO Test Suite">

<test name="UOLO Test">

<classes>

    <class name="testng.testone">
      <methods>
        <include name="newtest"/>
      </methods>
     </class>
</classes>

</test>
</suite> 














Shruthi

⇜Krishnan Mahadevan⇝

unread,
May 30, 2016, 7:52:39 AM5/30/16
to Selenium Users
Try changing 

<suite name="UOLO Test Suite">

to 

<suite name="UOLO Test Suite" verbose="3">


in your suite file and run again. You should start seeing the exception details. You should already be seeing the exception information in the TestNG generated reports as well.




Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

shruthi v v

unread,
May 30, 2016, 8:18:59 AM5/30/16
to seleniu...@googlegroups.com
I have added verbose="3" and re-run the test.seems to be problem with[ testng] org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally

console output :
 *********** INVOKED METHODS
   [testng]
   [testng]             testng.testone.newtest() 1911006827
   [testng]
   [testng] ***********
   [testng]
   [testng] Creating /var/lib/jenkins/jobs/ShruthiTest/workspace/NewTestNg/test-                                                                                        output/UOLO Test Suite/UOLO Test.html
   [testng] Creating /var/lib/jenkins/jobs/ShruthiTest/workspace/NewTestNg/test-                                                                                        output/UOLO Test Suite/UOLO Test.xml
   [testng] FAILED: newtest
   [testng] org.openqa.selenium.WebDriverException: unknown error: Chrome failed                                                                                         to start: exited abnormally
   [testng]   (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6                                                                                        b74ccc23cb636a),platform=Linux 4.4.10-22.54.amzn1.x86_64 x86_64) (WARNING: The s                                                                                        erver did not provide any stacktrace information)
   [testng] Command duration or timeout: 61.05 seconds
   [testng] Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-0                                                                                        4 16:17:10'
   [testng] System info: host: 'ip-172-31-9-218', ip: '172.31.9.218', os.name: '                                                                                        Linux', os.arch: 'amd64', os.version: '4.4.10-22.54.amzn1.x86_64', java.version:                                                                                         '1.8.0_45'
   [testng] Driver info: org.openqa.selenium.chrome.ChromeDriver
   [testng]     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native                                                                                         Method)
   [testng]     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeC                                                                                        onstructorAccessorImpl.java:62)
   [testng]     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Del                                                                                        egatingConstructorAccessorImpl.java:45)
   [testng]     at java.lang.reflect.Constructor.newInstance(Constructor.java:42                                                                                        2)
   [testng]     at org.openqa.selenium.remote.ErrorHandler.createThrowable(Error                                                                                        Handler.java:204)
   [testng]     at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed                                                                                        (ErrorHandler.java:156)
   [testng]     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebD                                                                                        river.java:605)
   [testng]     at org.openqa.selenium.remote.RemoteWebDriver.startSession(Remot                                                                                        eWebDriver.java:242)
   [testng]     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDr                                                                                        iver.java:128)
   [testng]     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDr                                                                                        iver.java:141)
   [testng]     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.j                                                                                        ava:170)
   [testng]     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.j                                                                                        ava:159)
   [testng]     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.j                                                                                        ava:116)
   [testng]     at testng.testone.newtest(testone.java:27)
   [testng]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   [testng]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces                                                                                        sorImpl.java:62)
   [testng]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet                                                                                        hodAccessorImpl.java:43)
   [testng]     at java.lang.reflect.Method.invoke(Method.java:497)
   [testng]     at org.testng.internal.MethodInvocationHelper.invokeMethod(Metho                                                                                        dInvocationHelper.java:74)
   [testng]     at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
   [testng]     at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846                                                                                        )
   [testng]     at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:11                                                                                        70)
   [testng]     at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMe                                                                                        thodWorker.java:125)
   [testng]     at org.testng.internal.TestMethodWorker.run(TestMethodWorker.jav                                                                                        a:109)
   [testng]     at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
   [testng]     at org.testng.TestRunner.privateRun(TestRunner.java:749)
   [testng]     at org.testng.TestRunner.run(TestRunner.java:600)
   [testng]     at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
   [testng]     at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
   [testng]     at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
   [testng]     at org.testng.SuiteRunner.run(SuiteRunner.java:223)
   [testng]     at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:                                                                                        52)
   [testng]     at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
   [testng]     at org.testng.TestNG.runSuitesSequentially(TestNG.java:1039)
   [testng]     at org.testng.TestNG.runSuitesLocally(TestNG.java:964)
   [testng]     at org.testng.TestNG.run(TestNG.java:900)
   [testng]     at org.testng.TestNG.privateMain(TestNG.java:1182)
   [testng]     at org.testng.TestNG.main(TestNG.java:1146)
   [testng]
   [testng]
   [testng] ===============================================
   [testng]     UOLO Test
   [testng]     Tests run: 1, Failures: 1, Skips: 0
   [testng] ===============================================


 














Shruthi

⇜Krishnan Mahadevan⇝

unread,
May 30, 2016, 10:44:12 PM5/30/16
to Selenium Users
Since am not sure if its due to a faulty chromedriver installation or a faulty chrome browser installation itself [ The error is due to one of those reasons ], you would need to try and do the following manually once :

1. Try spawning the chrome browser manually by invoking it via the command line. You should be able to spawn the browser.
2. If the browser spawns, then try spawning the chromedriver manually and you should see an output as below :

Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 9515
Only local connections are allowed.

The last part of the test would be to check if chromedriver is able to spawn the chrome browser properly. For that do the following from a terminal :

1. Spawn the chromedriver binary.
2. From another terminal invoke the below curl POST command [ You should see a chrome browser pop out ]

curl --data "{\"desiredCapabilities\": {}}" --header "Content-type: application/json"  http://localhost:9515/session


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

shruthi v v

unread,
Jun 2, 2016, 2:45:33 AM6/2/16
to seleniu...@googlegroups.com
Iam getting below error for running command
 curl --data "{\"desiredCapabilities\": {}}" --header "Content-type: application/json"  http://localhost:9515/session

output:
curl: (7) Failed to connect to localhost port 9515: Connection refused

When I replace localhost with my server ip address (http://52.77.152.154:9515/session) and hit enter then still shows as waiting for command line input .

Could you please send me command to Spawn the chromedriver binary and chrome browser manually 















Shruthi

⇜Krishnan Mahadevan⇝

unread,
Jun 2, 2016, 6:57:41 AM6/2/16
to Selenium Users
Shruthi

Could you please send me command to Spawn the chromedriver binary and chrome browser manually 

There is no special command to spawn the chromedriver binary. If its location has been added in your PATH variable, merely typing "chromedriver" in a terminal will invoke it. If not then you would need to navigate to the directory wherein chromedriver binary resides using "cd" command and then type "chromedriver".

That should do.

If you want chromedriver to give you "verbose" logs, then you start it with : chromedriver --verbose [ You can type chromedriver -h to see all the possible command line arguments ]


When I replace localhost with my server ip address (http://52.77.152.154:9515/session) and hit enter then still shows as waiting for command line input .

I guess you are perhaps experiencing the problem that is detailed in this SO link (The link is about OSX but I think its a problem with your loopback address in /etc/hosts file ) which is why curl doesn't work with localhost. That's immaterial (or is it) !
When you changed the IP to your server IP address did you see a browser window open up ? If you saw that, then it basically means that your environment setup is working fine i.e., you have correctly installed chrome browser and your chromedriver binary is successfully able to spawn a chrome browser via a JSONWireProtocol command [ the curl command is essentially what selenium will also do internally ]


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

shruthi v v

unread,
Jun 2, 2016, 7:50:11 AM6/2/16
to seleniu...@googlegroups.com
Thanks for replying Krishnan Mahadevan,

1.when I navigate to the directory wherein chromedriver binary resides using "cd" command and then type "chromedriver".throws an error as 

bash: chromedriver: command not found

when I type like ./chromedriver
output shown as Starting ChromeDriver (v2.9.248304) on port 9515  but I do not see browser opening up 

2.When I type  google-chrome it shows as [11434:11434:0602/114735:ERROR:browser_main_loop.cc(271)] Gtk: cannot open display:


















Shruthi

⇜Krishnan Mahadevan⇝

unread,
Jun 2, 2016, 8:25:54 AM6/2/16
to Selenium Users

2.When I type  google-chrome it shows as [11434:11434:0602/114735:ERROR:browser_main_loop.cc(271)] Gtk: cannot open display:
You should take a look at this post and see if that helps : http://superuser.com/a/392263

I think now its confirmed that your machine hasn't been setup properly to spawn a UI application.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Shawn McCarthy

unread,
Jun 2, 2016, 12:11:06 PM6/2/16
to Selenium Users
Chromedriver 2.9 is very old. You might want to go to version 2.21

shruthi v v

unread,
Jun 8, 2016, 9:23:01 AM6/8/16
to seleniu...@googlegroups.com
When I googled ,I got to know that I am suppose to install Xvfb to open any browsers on amazon AWS EC2 Linux machine  and I have done that using command "yum install Xvfb"

Now iam getting following error when I run the selenium test ,anyone has any idea what is going wrong here?please advice...

Google Chrome 51.0.2704.79 
ChromeDriver 2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a)
curl 7.40.0 (x86_64-redhat-linux-gnu) libcurl/7.40.0 NSS/3.21 Basic ECC zlib/1.2.8 libidn/1.18 libssh2/1.4.2
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets


org.openqa.selenium.WebDriverException: unknown error: an X display is required for keycode conversions, consider using Xvfb
   [testng]   (Session info: chrome=51.0.2704.79)
   [testng]   (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.4.11-23.53.amzn1.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)















Shruthi

On Mon, May 30, 2016 at 3:46 PM, shruthi v v <success...@gmail.com> wrote:

Serguei Kouzmine

unread,
Jun 10, 2016, 7:22:07 PM6/10/16
to Selenium Users
Hello Shruthi

All it is telling you is you have to set environment variable DISPLAY=0


If you xfvb listens to a different tcp port, change the value of DISPLAY accordingly,

You must be able to run chrome.  when you are everything else will work.


Thanks,

Let me know if you need further assistance


You can also look how my Vagrantbox for the same is configured on my github
https://github.com/sergueik/selenium_vagrant

or how a standalone shell command
e.g.
https://github.com/sergueik/selenium_java/blob/master/utils/node.sh
export HUB_IP_ADDRESS=127.0.0.1
export HUB_PORT=4444
export SELENIUM_JAR_VERSION=2.47.1
export DISPLAY_PORT=0
export ROLE=node
...
export DISPLAY=:$DISPLAY_PORT
# TODO : specify geometry of the display
Xvfb $DISPLAY -ac >/dev/null 2>&1 &
...
java $LAUNCHER_OPTS \
-classpath \
$SELENIUM_HOME/log4j-1.2.17.jar:$SELENIUM_HOME/selenium-server-standalone.jar: \
-Dlog4j.configuration=node.log4j.properties \
org.openqa.grid.selenium.GridLauncher \
-role node \
-host $NODE_HOST \
-port $NODE_PORT \
-hub http://${HUB_IP_ADDRESS}:${HUB_PORT}/hub/register \
-nodeConfig $CONFIG_FILE \
-browserTimeout 12000 -timeout 12000 \
-ensureCleanSession true \
-trustAllSSLCertificates

This command is for node, you may adjust the argument for standalone


Thanks

shruthi v v

unread,
Jun 12, 2016, 1:23:30 PM6/12/16
to seleniu...@googlegroups.com
Thanks for reply but how to check xfvb listens to which TCP port?














Shruthi

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Serguei Kouzmine

unread,
Aug 3, 2016, 11:19:12 PM8/3/16
to Selenium Users
Hello Shuthi

You can check running processes and find the arguments xvfb is running with
there DISPLAY value is also written to /var/log/.xvfb
 - you need to see on your system (I do not have a vm with xvfb / selenium running locally so can't test this part directly atm.


https://www.x.org/archive/X11R7.6/doc/man/man1/Xvfb.1.xhtml
Thanks
Serguei Kouzmine
Reply all
Reply to author
Forward
0 new messages