A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Category_model_SelectMainMenu.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Category_model.php
Line: 53
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 106
Function: SelectMainMenu
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(/home/anhtest2/public_html/application/cache/Category_model_SelectByParentArrayId.cache): failed to open stream: No such file or directory
Filename: drivers/Cache_file.php
Line Number: 275
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Category_model.php
Line: 60
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 109
Function: SelectByParentArrayId
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Trying to access array offset on value of type bool
Filename: drivers/Cache_file.php
Line Number: 277
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Category_model.php
Line: 60
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 109
Function: SelectByParentArrayId
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeylogo.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 124
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeyicon.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 125
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeyfacebook.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 126
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeyqr_zalo_group.cache): failed to open stream: No such file or directory
Filename: drivers/Cache_file.php
Line Number: 275
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 129
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Trying to access array offset on value of type bool
Filename: drivers/Cache_file.php
Line Number: 277
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 129
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeybanner_footer.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 137
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeymeta_image.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 144
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Lesson.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
[Cucumber TestNG] Bài 13: Cài đặt Cucumber Report và Allure Report | Anh Tester
NỘI
DUNG BÀI HỌC
✅Cài đặt Cucumber Report ✅Cài đặt Allure Report trong Cucumber TestNG
✅ Cài đặt Cucumber Report
Bản chất Cucumber Report là HTML giống với Extent Report. Nên cũng rất dễ dùng để di chuyển đi nơi khác. Để sử dụng Cucumber report thì đầu tiên chúng ta thêm phần cấu hình thư viện Cucumber Report vào trong pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<suiteXmlFiles>
<!-- Call Suite path -->
<suiteXmlFile>src/test/resources/suites/SuiteLoginCMS.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<!--https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting-->
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.7.5</version>
<executions>
<execution>
<id>execution</id>
<phase>test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>CucumberTestNG022023</projectName>
<skip>false</skip>
<outputDirectory>reports/CucumberReports/cucumber-reports</outputDirectory>
<inputDirectory>target/cucumber-reports</inputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<outputDirectory>reports/CucumberReports/cucumber-reports</outputDirectory> Đây là đường dẫn xuất ra Report sau khi chạy test<inputDirectory>target/cucumber-reports</inputDirectory> Đây là đường dẫn nạp data vào cho report khi chạy test
Tiếp theo thêm phần đường dẫn chỉ định để xuất ra report trong Test Runner cho từng class cụ thể
"html:target/cucumber-reports/TestRunnerCategoryCMS.html",
"json:target/cucumber-reports/TestRunnerCategoryCMS.json"
Chú ý là đặt tên file phân biệt giữa các class kẻo nó bị ghi đè. Nên góp ý là các bạn lấy tên class đặt cho tên file HTML và JSON xuất ra ở mỗi class là không bị trùng. Các bạn chú ý cái đường dẫn trỏ đến file suite xml để gọi cái class Test Runner trong pom.xml Cuối cùng là chạy test trực tiếp trong maven với lệnh mvn clean test Sau khi chạy xong thì Cucumber Report xuất ra đúng folder mà mình chỉ định bên trên Tại đây các bạn mở report trực tiếp trong IntelliJ IDEA hoặc mở thư mục source ra tìm file HTML của Cucumber Report chạy đều được. Các bạn có thể click vào link từng Test Case name để xem detail bên trong Yeah vậy là xong phần Cucumber Report cơ bản rồi đấy.
🔆 Execute trực tiếp nhiều file class Test Runner không cần chạy thông qua suite XML
Này nghĩa là Cucumber Framework tự động tìm tất cả các file class Test Runner mà có tên đoạn đầu chứa TestRunner để thực thi hết
Lưu ý : khi sử dụng trực tiếp file class TestRunner thì comment cái suite xml lại kẻo nó bị duplicated.
✅ Cài đặt Allure Report trong Cucumber
Allure report trong TestNG trước đây chúng ta đã cài đặt dùng nhiều rồi nên cũng biết Allure report là gì. Ở đây An chỉ cho các bạn cìa nó vào trong Cucumber vì trong Cucumber Framework thì cách thức triển khai report có vài chổ khác so với bên TestNG Framework.Đầu tiên add thư viện Allure Cucumber Report vào trong file pom.xml
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-cucumber7-jvm -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber7-jvm</artifactId>
<version>2.22.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.22.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-attachments -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-attachments</artifactId>
<version>2.22.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.19</version>
</dependency>
Tiếp theo thêm đoạn cấu hình đường dẫn để xuất ra Allure report trong phần plugin maven-surefire-plugin như bên dưới
<!-- Setup Allure report -->
<argLine>
-Dfile.encoding=UTF-8
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.19/aspectjweaver-1.9.19.jar"
</argLine>
<reportsDirectory>target/test-output</reportsDirectory>
<systemPropertyVariables>
<allure.results.directory>target/allure-results</allure.results.directory>
</systemPropertyVariables>
Tiếp theo thêm đoạn config Allure report trong các class Test Runner giống như Cucumber report bên trên
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"
Sau cùng là thực thi test và mở Allure report như trước đây với lệnh:
allure serve target/allure-results
🔆 Đính kèm screenshot vào report khi test case Fail
Các bạn vào chổ class Hook tìm đến @AfterStep để thêm đoạn chụp màn hình vào là xong
if (scenario.isFailed()) {
final byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "Screenshot Failed");
}
Yeah vậy là xong phần Allure report trong Cucumber rồi. Chúc các bạn làm suôn sẻ nhé 😁 Nhìn chung thì An đánh giá cao Allure report hơn là Cucumber report . Nó chi tiết đến tận các bước auto của Selenium .
Software Quality Engineer
Đường dẫu khó chân vẫn cần bước đi Đời dẫu khổ tâm vẫn cần nghĩ thấu
Chia sẻ khóa
học lên trang
Bạn có thể đăng khóa học của
chính bạn lên trang
Anh Tester để kiếm tiền