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:\Users\WB-ZJ3~1\AppData\Local\Temp\scoped_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必須去掉,否則還是會飄紅