extentreports 测试报告
只支持java、.Net
- 先在pom.xml文件中加入包引用
<!-- report--> <dependency> <groupId>com.vimalselvam</groupId> <artifactId>cucumber-extentsreport</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>3.0.6</version> </dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.40.2</version>
</dependency>
- 进入你的cucumber入口主类中
- CucumberOptions中加入插件的属性
- 在
@BeforeClass
注解方法中,可以使用setReportPath
方法指定插件的报告生成位置 - 在
@AfterClass
注解方法中,可以使用loadXMLConfig
方法指定报告配置文件的位置
@RunWith(Cucumber.class) @ContextConfiguration("classpath:cucumber.xml") @CucumberOptions( plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/extent-report/report.html"},//1 format = {"json:target/cucumber-report.json","pretty"},//2 features = {"src/test/resources/com/features/"}, glue = {"com.steps"}, tags = { "@login,@role" }) public class CucumberStart { @BeforeClass public static void setup() { ExtentProperties extentProperties = ExtentProperties.INSTANCE; extentProperties.setReportPath("target/extent-report/myreport.html"); // extentProperties.setExtentXServerUrl("http://localhost:1337"); extentProperties.setProjectName("xxx"); } @AfterClass public static void tearDown() { Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));//1 Reporter.setSystemInfo("user", System.getProperty("user.name")); Reporter.setSystemInfo("os", "Windows"); Reporter.setTestRunnerOutput("Sample test runner output message"); } }
extent-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <extentreports> <configuration> <theme>dark</theme> <encoding>UTF-8</encoding> <documentTitle>Cucumber Extent Reports</documentTitle> <reportName>Cucumber Extent Reports</reportName> <!--<reportHeadline> - v1.0.0</reportHeadline>--> <protocol>https</protocol> <dateFormat>yyyy-MM-dd</dateFormat> <timeFormat>HH:mm:ss</timeFormat> <scripts> <![CDATA[ $(document).ready(function() { }); ]]> </scripts> <!-- custom styles --> <styles> <![CDATA[ ]]> </styles> </configuration> </extentreports>
基础环境搭建后,运行报错
Exception in thread "main" cucumber.runtime.CucumberException: Failed to instantiate public cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader) with [cucumber.runtime.io.MultiLoader@15bb6bea]
可能是pom.xml文件配置错误,或者maven包未更新下来
主意配置:
cucmber-junit
cucumber-java
junit
Error:(9, 8) java: 类TestSteps是公共的, 应在名为 TestSteps.java 的文件中声明
public类一个文件只能有一个,并且和文件名要相同
Error:(11, 6) java: 找不到符号
符号: 类 When
位置: 类 com.future.sys.AppTest
引入包
import cucumber.api.PendingException;
import cucumber.api.java.en.When;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
cucumber.runtime.CucumberException:
Classes annotated with @RunWith(Cucumber.class) must not define any
Step Definition or Hook methods. Their sole purpose is to serve as
an entry point for JUnit. Step Definitions and Hooks should be defined
in their own classes. This allows them to be reused across features.
Offending class: class com.future.sys.AppTest
@RunWith(Cucumber.class)不能定义任何步骤或钩子方法。他们唯一的目的是充当JUnit的切入点。应在他们自己的classes进行定义和挂钩。允许它们跨功能重用。
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
未设置Driver插件,下载driver插件,放置目录下,然后再程序classes中配置
System.setProperty("webdriver.chrome.driver","C:\chromedriver.exe");
org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"(178AED370C406FDFCCBE0E4F62CA1D53)","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=64.0.3282.186)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'MININT-VAGEPAQ', ip: '30.40.97.11', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:UsersWB-ZJ3~1AppDataLocalTempscoped_dir47624_12669}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=64.0.3282.186, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, cssSelectorsEnabled=true}]
Session ID: e14f8466a91a11e2e5f98e93a7e7c7df
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
driver版本与浏览器版本不兼容,参考
chromedriver版本 | 支持的Chrome版本 |
v2.35 |
v62-64 |
v2.34 |
v61-63 |
v2.33 |
v60-62 |
v2.32 |
v59-61 |
v2.31 |
v58-60 |
v2.30 |
v58-60 |
v2.29 |
v56-58 |
v2.28 |
v55-57 |
v2.27 |
v54-56 |
v2.26 |
v53-55 |
v2.25 |
v53-55 |
v2.24 |
v52-54 |
v2.23 |
v51-53 |
v2.22 |
v49-52 |
v2.21 |
v46-50 |
v2.20 |
v43-48 |
v2.19 |
v43-47 |
v2.18 |
v43-46 |
v2.17 |
v42-43 |
v2.13 |
v42-45 |
v2.15 |
v40-43 |
v2.14 |
v39-42 |
v2.13 |
v38-41 |
v2.12 |
v36-40 |
v2.11 |
v36-40 |
v2.10 |
v33-36 |
v2.9 |
v31-34 |
v2.8 |
v30-33 |
v2.7 |
v30-33 |
v2.6 |
v29-32 |
v2.5 |
v29-32 |
v2.4 |
v29-32 |
附:
所有chromedriver均可在下面链接中下载到:
http://chromedriver.storage.googleapis.com/index.html
运行story时,打开多个浏览器
使用全局变量存储Driver
点击菜单后,获取不到ifream中元素
>>> 进入Iframe进行处理
@ContextConfiguration("classpath:cucumber.xml")飘红报错
在pop.xml中配置:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.0.2.RELEASE</version> </dependency>
注意test必须去掉,否则还是会飘红