Search code examples
mavenseleniumjenkinscucumbercucumber-junit

Browser not opening when running Cucumber tests from Jenkins


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: [email protected]
@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?


Solution

  • 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