【发布时间】:2016-07-23 17:45:59
【问题描述】:
我正在尝试从配置了 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>
您能帮我解决这个问题吗?
【问题讨论】:
-
您使用的是哪个网络驱动程序。 jenkins 是否在登录用户的上下文中运行,以便能够启动 UI 会话?
-
@MartinBrugger 我使用 FirefoxDriver,当我从 Eclipse 执行项目时浏览器会打开,但当我从 Jenkins 执行时无法工作
-
我不知道您是如何得出浏览器无法打开的结论,因为您收到的错误是
NoSuchElement异常,只有当已经存在 WebDriver 对象时才会发生这种情况。 -
此外,我看不出这与 Cucumber 有什么关系。
-
你如何运行 Jenkins?请参阅cimgf.com/2015/05/26/setting-up-jenkins-ci-on-a-mac-2 上的“允许 Jenkins 运行 GUI 应用程序”或切换到 phantomJS 网络驱动程序以便能够无头运行测试
标签: maven selenium jenkins cucumber cucumber-junit