Created
May 6, 2026 18:29
-
-
Save borodicht/8a062770fa13ec1de3eb141c5c8a5ba6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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