Thursday, 24 November 2022

TestNG Project add_to_cart.java file test case code

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Add_To_Cart extends Load_Test{

@BeforeTest
public void before_add_to_cart(){

}

@Test
public void test_Add_to_cart(){
ExtentTest test = extent.createTest("Add To Cart Button Test ");
try{
driver.findElement(By.id("add-to-cart-sauce-labs-backpack")).click();
String text = driver.findElement(By.id("add-to-cart-sauce-labs-backpack")).getText();
if(text == "REMOVE"){
test.log(Status.INFO,"Add to cart button test: Pass");
extent.flush();
}
else{
test.log(Status.INFO,"Add to cart button test: Fail");
extent.flush();
}
}
catch (Throwable t){
System.out.println("Add to cart Exception: "+t);
}
}

@AfterTest
public void after_add_to_cart(){

}

}

--
With Warm REGARDS,

En. S. WANKHEDE

No comments:

Post a Comment

Welcome, happy learning

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...