从Jenkins运行Cucumber测试时浏览器无法打开

时间:2016-07-23 17:46:00

标签: maven selenium jenkins cucumber cucumber-junit

我正在尝试从配置了Maven的Jenkins运行Cucumber Selenium项目,但是浏览器没有打开并且执行失败。

当我使用mvn test从命令提示符执行相同的项目时,执行按预期进行。

以下是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'

以下是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>

你能帮我解决一下这个问题吗?

2 个答案:

答案 0 :(得分:0)

相信您正在运行Jenkins作为服务,这将显示后台进程。做以下事情,并希望这将锻炼

运行 - &gt; Services.msc

右键点击jenkins,然后从 登录 标签

中选择 允许服务与桌面进行交互 >

答案 1 :(得分:0)

我的执行也可以从Eclipse以及命令提示符下的mvn test中运行。

我遇到了类似的问题,在Jenkins中我可以看到测试在“控制台输出”下运行,但看不到浏览器正在运行。只有在我启用了服务中的交互式服务检测并将其设置为手动后,此方法才起作用。

您将能够看到一个弹出式窗口,其中显示“此计算机上正在运行的程序正在尝试显示消息”,并带有以下选项:

  • 查看消息
  • 稍后问我

要查看测试的运行情况,只需单击“查看消息”,您就可以查看测试的运行情况。如果您想返回詹金斯,只需单击“返回”。