This repository has been archived by the owner on Dec 14, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
170 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
10 changes: 0 additions & 10 deletions
10
saucedemo-parallel/src/test/java/com/saucelabs/saucedemo/SauceDemoNavigation.java
This file was deleted.
Oops, something went wrong.
67 changes: 32 additions & 35 deletions
67
saucedemo-parallel/src/test/java/com/saucelabs/saucedemo/pages/InventoryPage.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,55 @@ | ||
package com.saucelabs.saucedemo.pages; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
public class InventoryPage { | ||
private WebDriver driver; | ||
InventoryPage() {} | ||
|
||
public InventoryPage(WebDriver driver) { | ||
this.driver = driver; | ||
PageFactory.initElements(driver, this); | ||
} | ||
|
||
@FindBy(className = "header_label") | ||
private WebElement headerLabel; | ||
|
||
@FindBy(className = "product_sort_container") | ||
private WebElement sortList; | ||
@FindBy(className = "inventory_container") | ||
private WebElement inventoryContainer; | ||
|
||
@FindBy(className ="add-to-cart-button") | ||
private WebElement addToCart; | ||
@FindBy(className = "inventory_list") | ||
private WebElement inventoryList; | ||
|
||
@FindBy(className ="remove-from-cart-button") | ||
private WebElement removeFromCartButton; | ||
@FindBy(className = "header_secondary_container") | ||
private WebElement inventoryHeader; | ||
|
||
@FindBy(className = "shopping_cart_badge") | ||
private WebElement shoppingCartBadge; | ||
/** | ||
* Returns the Div containing the item specified (zero-indexed) | ||
* @param itemNumber | ||
* @return | ||
*/ | ||
private WebElement getItemNumber(int itemNumber) { | ||
return inventoryList.findElement(By.cssSelector(String.format("div.inventory_item:nth-of-type(%d)", itemNumber))); | ||
} | ||
|
||
@FindBy(className = "inventory_container") | ||
private WebElement inventoryContainer; | ||
public String getItemName(int itemNumber) { | ||
WebElement itemName = getItemNumber(itemNumber).findElement(By.className("inventory_item_name")); | ||
return itemName.getText(); | ||
} | ||
|
||
public boolean isOnPage() { | ||
WebDriverWait wait = new WebDriverWait(driver, 5); | ||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("header_label"))); | ||
return headerLabel.isDisplayed(); | ||
public String getItemDescription(int itemNumber) { | ||
WebElement itemDesc = getItemNumber(itemNumber).findElement(By.className("inventory_item_desc")); | ||
return itemDesc.getText(); | ||
} | ||
|
||
public void addItemToCart() { | ||
addToCart.click(); | ||
public String getItemPrice(int itemNumber) { | ||
WebElement itemPrice = getItemNumber(itemNumber).findElement(By.className("inventory_item_price")); | ||
return itemPrice.getText(); | ||
} | ||
|
||
public void removeItemFromCart() { | ||
removeFromCartButton.click(); | ||
public void addItemToCart(int itemNumber) { | ||
WebElement addToCart = getItemNumber(itemNumber).findElement(By.className("btn_primary")); | ||
addToCart.click(); | ||
} | ||
|
||
public int getNumberOfItemsInCart() { | ||
return Integer.valueOf(shoppingCartBadge.getText()); | ||
public boolean isOnPage() { | ||
return inventoryHeader.isDisplayed(); | ||
} | ||
|
||
public int getItemsInPage() { | ||
return Integer.valueOf(inventoryContainer.getText()); | ||
public boolean itemAddedToCart(int itemNumber) { | ||
return getItemNumber(itemNumber).findElement(By.className("btn_secondary")).isDisplayed(); | ||
} | ||
} |
This file contains 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
24 changes: 24 additions & 0 deletions
24
saucedemo-parallel/src/test/java/com/saucelabs/saucedemo/pages/SauceDemoNavigation.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.saucelabs.saucedemo.pages; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.support.PageFactory; | ||
|
||
public class SauceDemoNavigation { | ||
private WebDriver driver; | ||
public SauceDemoNavigation(WebDriver driver) { | ||
this.driver = driver; | ||
} | ||
|
||
public LoginPage goToLoginPage() { | ||
LoginPage loginPage = new LoginPage(); | ||
PageFactory.initElements(driver, loginPage); | ||
driver.get(loginPage.getUrl()); | ||
return loginPage; | ||
} | ||
|
||
public InventoryPage getInventoryPage() { | ||
InventoryPage inventoryPage = new InventoryPage(); | ||
PageFactory.initElements(driver, inventoryPage); | ||
return inventoryPage; | ||
} | ||
} |
This file contains 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
52 changes: 42 additions & 10 deletions
52
saucedemo-parallel/src/test/java/com/saucelabs/saucedemo/tests/InventoryTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,50 @@ | ||
package com.saucelabs.saucedemo.tests; | ||
|
||
import com.saucelabs.saucedemo.pages.SauceDemoNavigation; | ||
import com.saucelabs.saucedemo.pages.InventoryPage; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.stream.IntStream; | ||
|
||
public class InventoryTest extends BaseWebDriverTest { | ||
@Test | ||
public void addOneItemToCart() {} | ||
|
||
public void addItemsToCart(int items) { | ||
IntStream.range(0, items).forEach(i -> { | ||
InventoryPage page = new InventoryPage(getWebDriver()); | ||
page.addItemToCart(); | ||
}); | ||
@Test(dataProvider = "sauceBrowsers") | ||
public void testItem3Label(String browser, String browserVersion, String platformName, RunType runType) { | ||
this.createDriver(browser, browserVersion, platformName, "testItem3Label", runType); | ||
|
||
SauceDemoNavigation navigation = new SauceDemoNavigation(getWebDriver()); | ||
|
||
navigation.goToLoginPage().login("standard_user", "secret_sauce"); | ||
InventoryPage inventoryPage = navigation.getInventoryPage(); | ||
Assert.assertEquals("Sauce Labs Bolt T-Shirt", inventoryPage.getItemName(3)); | ||
} | ||
|
||
@Test(dataProvider = "sauceBrowsers") | ||
public void testItem3Price(String browser, String browserVersion, String platformName, RunType runType) { | ||
this.createDriver(browser, browserVersion, platformName, "testItem3Price", runType); | ||
|
||
SauceDemoNavigation navigation = new SauceDemoNavigation(getWebDriver()); | ||
navigation.goToLoginPage().login("standard_user", "secret_sauce"); | ||
InventoryPage inventoryPage = navigation.getInventoryPage(); | ||
Assert.assertEquals("$15.99", inventoryPage.getItemPrice(3)); | ||
} | ||
|
||
@Test(dataProvider = "sauceBrowsers") | ||
public void testItem3Description(String browser, String browserVersion, String platformName, RunType runType) { | ||
this.createDriver(browser, browserVersion, platformName, "testItem3Description", runType); | ||
|
||
SauceDemoNavigation navigation = new SauceDemoNavigation(getWebDriver()); | ||
navigation.goToLoginPage().login("standard_user", "secret_sauce"); | ||
InventoryPage inventoryPage = navigation.getInventoryPage(); | ||
Assert.assertEquals("Get your testing superhero on with the Sauce Labs bolt T-shirt. From American Apparel, 100% ringspun combed cotton, heather gray with red bolt.", inventoryPage.getItemDescription(3)); | ||
} | ||
|
||
@Test(dataProvider = "sauceBrowsers") | ||
public void testAddOneItem(String browser, String browserVersion, String platformName, RunType runType) { | ||
this.createDriver(browser, browserVersion, platformName, "testAddOneItem", runType); | ||
|
||
SauceDemoNavigation navigation = new SauceDemoNavigation(getWebDriver()); | ||
navigation.goToLoginPage().login("standard_user", "secret_sauce"); | ||
InventoryPage inventoryPage = navigation.getInventoryPage(); | ||
inventoryPage.addItemToCart(3); | ||
Assert.assertTrue(inventoryPage.itemAddedToCart(3)); | ||
} | ||
} |
This file contains 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