0

I'm trying to run Cucumber Selenium project from Jenkins configured with Maven, but the browser is not opening and execution fails.

When I execute the same project from command prompt using mvn test, the execution happens as expected.

Below is the console output from Jenkins

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.srinimarva.bigbasket.runner.customer.LoginATTest
#Author: Srinivasan Ramu
#Email: mailtorsrinivasan@gmail.com
@Login
Feature: To test the Login functionality using BigBasket, Facebook and Google credentials

  Background:                                             [90m# com/srinimarva/bigbasket/features/customer/Login.feature:6[0m
    [32mGiven [0m[32mI open "[0m[32m[1mMozilla[0m[32m" browser to execute "[0m[32m[1mLoginTest[0m[32m"[0m [90m# CommonStepDefs.I_open_browser(String,String)[0m
    [32mAnd [0m[32mI connect to "[0m[32m[1mhttp://www.bigbasket.com[0m[32m"[0m           [90m# CommonStepDefs.connectURL(String)[0m
Unable to locate element: {"method":"xpath","selector":"html/body/div[18]/div[1]/div[2]/div[3]/span[1]/a"}
Command duration or timeout: 30.09 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'Srinivasans-MacBook-Pro.local', ip: '10.231.233.99', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.5', java.version: '1.7.0_79'

Below is the contents of pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.srinimarva.bigbasket</groupId>
  <artifactId>BigBasket</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>BigBasket</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-junit</artifactId>
      <version>1.2.4</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>1.2.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-core</artifactId>
      <version>1.2.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.53.1</version>
    </dependency>
  </dependencies>
</project>

Could you please help me in resolving the issue?

Srinivasan Ramu
  • 1,033
  • 4
  • 11
  • 23
  • Which webdriver are you using. Is jenkins running in context of a logged in user so it is able to start a UI session? – Martin Brugger Jul 24 '16 at 11:43
  • @MartinBrugger I use FirefoxDriver and the browser opens when I execute the project from Eclipse but does not work when I execute if from Jenkins – Srinivasan Ramu Jul 24 '16 at 14:13
  • I don't know how you came to a conclusion that your browser does not open because the error you are getting is a `NoSuchElement` exception which can only happen when there already is a WebDriver object. – Eugene S Jul 24 '16 at 14:40
  • Moreover, I don't see how this is related to Cucumber. – Eugene S Jul 24 '16 at 14:41
  • @EugeneS But why I do not see the Firefox browser opening with the code Webdriver browser = new FirefoxDriver(); – Srinivasan Ramu Jul 24 '16 at 15:12
  • 1
    How do you run Jenkins? see "Allow Jenkins to Run GUI Applications" on http://www.cimgf.com/2015/05/26/setting-up-jenkins-ci-on-a-mac-2/ or switch to the phantomJS webdriver in order to be able to run the tests headless – Martin Brugger Jul 24 '16 at 15:37

2 Answers2

0

Believe you are running Jenkins as a service and this will show a background process. Do the following and hope this will workout

Run -> Services.msc

Right click on jenkins and select Allow Service to interact with Desktop from Log On Tab

Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54
0

My execution was working too from Eclipse as well as mvn test from the command prompt.

I faced a similar issue where I could see the test being run under 'Console Output' in Jenkins but couldn't see the browser running. It only worked after I enabled Interactive Services Detection from services and set it to Manual.

You will be able to see a popup that says 'A program running on this computer is trying to display a message' with options:

  • View the message
  • Ask me later

To view your test running simply click 'View the message' you will be able to see your test being run. If you want to return to Jenkins simple click 'Return'.

zagoo2000
  • 175
  • 1
  • 3
  • 10