Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created May 6, 2026 18:29
Show Gist options
  • Select an option

  • Save borodicht/8a062770fa13ec1de3eb141c5c8a5ba6 to your computer and use it in GitHub Desktop.

Select an option

Save borodicht/8a062770fa13ec1de3eb141c5c8a5ba6 to your computer and use it in GitHub Desktop.
package tests;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class CartTest extends BaseTest {
String expectedProductName = "Sauce Labs Backpack";
String expectedPriceOfProduct = "29.99";
@Test
public void checkCart() {
SoftAssert softAssert = new SoftAssert();
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("name")).sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.className("submit-button")).click();
driver.findElement(By.xpath("//*[@id='add-to-cart-sauce-labs-backpack']")).click();
driver.findElement(By.xpath("//*[@id='shopping_cart_container']/a")).click();
String actualProductName = driver.findElement(By.xpath("//div[@class='inventory_item_name' and text()='Sauce Labs Backpack']")).getText();
String actualPriceOfProduct = driver.findElement(By.xpath("//div[@class='cart_item' and .//div[text()='Sauce Labs Backpack']]//div[@class='inventory_item_price']")).getText().replace("$", "");
softAssert.assertEquals(actualProductName, expectedProductName, "Название товара не совпадает.");
softAssert.assertEquals(actualPriceOfProduct, expectedPriceOfProduct, "Стоимость товара не совпадает.");
softAssert.assertAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment