Skip to content

Commit c74e9e3

Browse files
Updated yml with docker
1 parent d9e5d0a commit c74e9e3

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<maven.compiler.target>11</maven.compiler.target>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<logback.version>1.5.9</logback.version>
18-
<chaintest.version>1.0.3</chaintest.version>
18+
<chaintest.version>1.0.4</chaintest.version>
1919
</properties>
2020
<dependencies>
2121
<dependency>
@@ -28,6 +28,11 @@
2828
<artifactId>testng</artifactId>
2929
<version>7.10.2</version>
3030
</dependency>
31+
<dependency>
32+
<groupId>org.seleniumhq.selenium</groupId>
33+
<artifactId>selenium-java</artifactId>
34+
<version>4.27.0</version>
35+
</dependency>
3136
<dependency>
3237
<groupId>org.slf4j</groupId>
3338
<artifactId>slf4j-api</artifactId>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
package reporting;
22

33
import com.aventstack.chaintest.plugins.ChainTestListener;
4+
import com.aventstack.chaintest.service.ChainPluginService;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.chrome.ChromeDriver;
7+
import org.testng.ITestResult;
8+
import org.testng.annotations.AfterMethod;
9+
import org.testng.annotations.BeforeMethod;
410
import org.testng.annotations.Listeners;
11+
import java.time.Duration;
512

613
@Listeners(ChainTestListener.class)
714
public class RootTest {
15+
WebDriver driver;
16+
17+
@BeforeMethod
18+
public void setUp() {
19+
driver = new ChromeDriver();
20+
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
21+
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(5));
22+
driver.manage().window().maximize();
23+
}
24+
25+
@AfterMethod
26+
public void attachScreenShot(final ITestResult result) {
27+
try {
28+
final byte[] bytes = new byte[]{};
29+
final String qualifiedName = result.getMethod().getQualifiedName();
30+
ChainPluginService.getInstance().embed(qualifiedName, bytes, "image/png");
31+
} catch (Exception e) {
32+
throw new RuntimeException(e);
33+
}
34+
}
35+
36+
@AfterMethod(dependsOnMethods = "attachScreenShot")
37+
public void tearDown() {
38+
driver.quit();
39+
}
40+
841
}
42+
43+

src/test/java/reporting/TestUtils.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
package reporting;
22

3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebElement;
35
import org.testng.Assert;
6+
import org.testng.annotations.BeforeMethod;
47
import org.testng.annotations.Test;
58

69
public class TestUtils extends RootTest {
710

11+
@BeforeMethod(dependsOnMethods = "setUp")
12+
public void setUpPage() {
13+
driver.get("https://www.saucedemo.com/v1/");
14+
}
15+
816
@Test
9-
public void firstTest(){
10-
Assert.assertTrue(true);
17+
public void verify_Login_Logo_Is_Available() {
18+
WebElement logo_Login = driver.findElement(By.xpath("//div[@class='login_logo']"));
19+
Assert.assertTrue(logo_Login.isDisplayed(), "Login logo not displayed");
1120
}
1221

1322
@Test
14-
public void secondTest(){
15-
Assert.assertTrue(true);
23+
public void verify_Error_Message_Displayed_For_Empty_Credentials() {
24+
driver.findElement(By.id("user-name")).sendKeys("");
25+
driver.findElement(By.id("password")).sendKeys("");
26+
driver.findElement(By.id("login-button")).click();
27+
String errorMsg = driver.findElement(By.xpath("//h3")).getText();
28+
Assert.assertTrue(errorMsg.contains("Username is required"));
1629
}
1730

1831
@Test
19-
public void thirdTest(){
20-
Assert.assertTrue(true);
32+
public void verify_User_Can_Login_With_Valid_Credentials() {
33+
driver.findElement(By.id("user-name")).sendKeys("standard_user");
34+
driver.findElement(By.id("password")).sendKeys("secret_sauce");
35+
driver.findElement(By.id("login-button")).click();
36+
String pageTitle = driver.findElement(By.xpath("//div[@class='product_label']")).getText();
37+
Assert.assertEquals(pageTitle, "Products");
2138
}
2239

2340

0 commit comments

Comments
 (0)