Skip to content

Commit 8a1da32

Browse files
committed
Update lesson 34 - Allure Report
1 parent 23293d1 commit 8a1da32

File tree

11 files changed

+885
-47
lines changed

11 files changed

+885
-47
lines changed

pom.xml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,61 @@
102102
<version>5.0.9</version>
103103
</dependency>
104104

105+
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
106+
<dependency>
107+
<groupId>io.qameta.allure</groupId>
108+
<artifactId>allure-testng</artifactId>
109+
<version>2.21.0</version>
110+
</dependency>
111+
112+
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-attachments -->
113+
<dependency>
114+
<groupId>io.qameta.allure</groupId>
115+
<artifactId>allure-attachments</artifactId>
116+
<version>2.21.0</version>
117+
</dependency>
118+
119+
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
120+
<dependency>
121+
<groupId>org.aspectj</groupId>
122+
<artifactId>aspectjweaver</artifactId>
123+
<version>1.9.19</version>
124+
</dependency>
125+
126+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
127+
<dependency>
128+
<groupId>org.projectlombok</groupId>
129+
<artifactId>lombok</artifactId>
130+
<version>1.18.26</version>
131+
<scope>provided</scope>
132+
</dependency>
105133

106-
107134
</dependencies>
108135

136+
<build>
137+
<pluginManagement>
138+
<plugins>
139+
<plugin>
140+
<groupId>org.apache.maven.plugins</groupId>
141+
<artifactId>maven-surefire-plugin</artifactId>
142+
<version>3.0.0</version>
143+
<configuration>
144+
<suiteXmlFiles>
145+
<!-- Call Suite name -->
146+
<suiteXmlFile>suites/SuiteLoginTest.xml</suiteXmlFile>
147+
</suiteXmlFiles>
148+
<argLine>
149+
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.19/aspectjweaver-1.9.19.jar"
150+
</argLine>
151+
<testFailureIgnore>true</testFailureIgnore>
152+
<systemPropertyVariables>
153+
<!--Đường dẫn xuất ra report-->
154+
<allure.results.directory>target/allure-results</allure.results.directory>
155+
</systemPropertyVariables>
156+
</configuration>
157+
</plugin>
158+
</plugins>
159+
</pluginManagement>
160+
</build>
161+
109162
</project>

reports/extentreport/extentreport.html

Lines changed: 780 additions & 29 deletions
Large diffs are not rendered by default.

src/main/java/anhtester/com/keywords/WebUI.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import anhtester.com.reports.ExtentTestManager;
44
import anhtester.com.utils.LogUtils;
55
import com.aventstack.extentreports.Status;
6+
import io.qameta.allure.Step;
67
import org.openqa.selenium.*;
78
import org.openqa.selenium.interactions.Actions;
89
import org.openqa.selenium.support.ui.ExpectedCondition;
@@ -46,6 +47,7 @@ public static WebElement highLightElement(By by) {
4647
return getWebElement(by);
4748
}
4849

50+
@Step("Right click on element {0}")
4951
public static void rightClickElement(By by) {
5052
waitForElementVisible(by);
5153
Actions action = new Actions(getDriver());
@@ -54,20 +56,23 @@ public static void rightClickElement(By by) {
5456
ExtentTestManager.logMessage(Status.PASS, "Right click on element " + by);
5557
}
5658

59+
@Step("Open URL: {0}")
5760
public static void openURL(String URL) {
5861
getDriver().get(URL);
5962
waitForPageLoaded();
6063
LogUtils.info("Open URL: " + URL);
6164
ExtentTestManager.logMessage(Status.PASS, "Open URL: " + URL);
6265
}
6366

67+
@Step("Get current URL")
6468
public static String getCurrentUrl() {
6569
waitForPageLoaded();
6670
LogUtils.info("Get Current URL: " + getDriver().getCurrentUrl());
6771
ExtentTestManager.logMessage(Status.PASS, "Get Current URL: " + getDriver().getCurrentUrl());
6872
return getDriver().getCurrentUrl();
6973
}
7074

75+
@Step("Click on element {0}")
7176
public static void clickElement(By by) {
7277
waitForElementVisible(by);
7378
highLightElement(by);
@@ -76,13 +81,15 @@ public static void clickElement(By by) {
7681
ExtentTestManager.logMessage(Status.PASS, "Click on element " + by);
7782
}
7883

84+
@Step("Set text {1} on element {0}")
7985
public static void setText(By by, String value) {
8086
waitForElementVisible(by);
8187
getWebElement(by).sendKeys(value);
8288
LogUtils.info("Set text " + value + " on element " + by);
8389
ExtentTestManager.logMessage(Status.PASS, "Set text " + value + " on element " + by);
8490
}
8591

92+
@Step("Get text of element {0}")
8693
public static String getTextElement(By by) {
8794
waitForElementVisible(by);
8895
LogUtils.info("Get text of element " + by);
@@ -92,6 +99,7 @@ public static String getTextElement(By by) {
9299
return getWebElement(by).getText();
93100
}
94101

102+
@Step("Get attribure {1} value of element {0}")
95103
public static String getAttributeElement(By by, String attributeName) {
96104
waitForElementVisible(by);
97105
LogUtils.info("Get attribute value of element " + by);
@@ -116,11 +124,6 @@ public static void scrollToElement(By by) {
116124

117125
}
118126

119-
public static void scrollToElementWithRobot(By by) {
120-
//Dùng Robot class
121-
122-
}
123-
124127
public static void sleep(double second) {
125128
try {
126129
Thread.sleep((long) (1000 * second));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package anhtester.com.reports;
2+
3+
import anhtester.com.drivers.DriverManager;
4+
import io.qameta.allure.Attachment;
5+
import org.openqa.selenium.OutputType;
6+
import org.openqa.selenium.TakesScreenshot;
7+
8+
public class AllureManager {
9+
//Text attachments for Allure
10+
@Attachment(value = "{0}", type = "text/plain")
11+
public static String saveTextLog(String message) {
12+
return message;
13+
}
14+
15+
//Screenshot attachments for Allure
16+
@Attachment(value = "Page screenshot", type = "image/png")
17+
public static byte[] saveScreenshotPNG() {
18+
return ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
19+
}
20+
}

src/test/java/anhtester/com/dataproviders/DataLogin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
public class DataLogin {
88
@DataProvider(name = "dataProviderLoginCRM", parallel = true)
99
public Object[][] dataLoginCRM() {
10-
return new Object[][]{{"admin@example.com", "123456"}, {"admin2@example.com", "123456"}, {"admin3@example.com", "123456"}};
10+
return new Object[][]{{"admin@example.com", "123456"}, {"admin@example.com", "123456"}, {"admin3@example.com", "123456"}};
1111
}
1212

1313
@DataProvider(name = "dataProviderLoginCMS", parallel = true)
1414
public Object[][] dataLoginCMS() {
15-
return new Object[][]{{"admin1@example.com", "123456", 123}, {"admin2@example.com", "123456", 1234}};
15+
return new Object[][]{{"admin@example.com", "123456", 123}, {"admin@example.com", "123456", 1234}};
1616
}
1717

1818
@DataProvider(name = "data_provider_login_excel")

src/test/java/anhtester/com/listeners/TestListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import anhtester.com.helpers.CaptureHelper;
44
import anhtester.com.helpers.PropertiesHelper;
5+
import anhtester.com.reports.AllureManager;
56
import anhtester.com.reports.ExtentReportManager;
67
import anhtester.com.reports.ExtentTestManager;
78
import anhtester.com.utils.LogUtils;
@@ -61,6 +62,10 @@ public void onTestFailure(ITestResult result) {
6162
ExtentTestManager.addScreenShot(result.getName());
6263
ExtentTestManager.logMessage(Status.FAIL, result.getThrowable().toString());
6364
ExtentTestManager.logMessage(Status.FAIL, result.getName() + " is failed.");
65+
66+
//Allure Report
67+
//AllureManager.saveTextLog(result.getName() + " is failed.");
68+
AllureManager.saveScreenshotPNG();
6469
}
6570

6671
@Override

src/test/java/anhtester/com/testcases/CustomersTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void testAddNewCustomer(Method method) {
3333
addCustomerPage = customersPage.clickNewCustomerButton();
3434

3535
//Addison, Joseph, Adorno, Theodor, Keiko, Bailey, Philip James
36-
String CUSTOMER_NAME = "Theodor";
36+
String CUSTOMER_NAME = "Keiko";
3737
addCustomerPage.AddDataNewCustomer(CUSTOMER_NAME);
3838

3939
//Mở lại trang Customer
@@ -43,7 +43,7 @@ public void testAddNewCustomer(Method method) {
4343
//Click vào giá trị Customer Name dòng đầu tiên
4444
customerDetailPage = customersPage.clickOnFirstRowCustomerName();
4545
//Check Customer Detail
46-
customerDetailPage.checkCustomerDetail("Theodor");
46+
customerDetailPage.checkCustomerDetail("Keiko");
4747

4848
}
4949

src/test/java/anhtester/com/testcases/LoginTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ public class LoginTest extends BaseTest {
2626
@Test
2727
public void testSetDataToExcel() {
2828
loginPage = new LoginPage();
29-
3029
ExcelHelper excelHelper = new ExcelHelper();
3130
excelHelper.setExcelFile("src/test/resources/datatest/CRM.xlsx", "Login");
32-
3331
loginPage.login(excelHelper.getCellData(ConstantData.EMAIL, 1), excelHelper.getCellData("PASSWORD", 1));
34-
3532
//Chạy tới dòng này nghĩa là Passed
3633
excelHelper.setCellData("Passed", 1, "RESULT");
37-
3834
}
3935

4036
@Test(dataProvider = "dataProviderLoginCRM", dataProviderClass = DataLogin.class)
2.43 KB
Binary file not shown.

suites/SuiteCustomerTest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
2+
3+
<suite name="Suite Login Test" verbose="1">
4+
5+
<test name="Login Test on Chrome">
6+
<parameter name="browser" value="chrome"/>
7+
<classes>
8+
<class name="anhtester.com.testcases.CustomersTest">
9+
</class>
10+
</classes>
11+
</test>
12+
13+
</suite>

0 commit comments

Comments
 (0)