Created
December 17, 2024 16:06
-
-
Save borodicht/6b725348dc28a382afca02d8aead9fa6 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 pages; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
public class ProductsPage { | |
WebDriver driver; | |
By title = By.cssSelector("[data-test=title]"); | |
String addToCartPattern = "//div[text()='%s']//ancestor::div[@class='inventory_item']//button"; | |
public ProductsPage(WebDriver driver) { | |
this.driver = driver; | |
} | |
public String getTitle() { | |
return driver.findElement(title).getText(); | |
} | |
public void addToCart(String product) { | |
driver.findElement(By.xpath(String.format(addToCartPattern, product))).click(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment