-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckoutStepTwo.java
More file actions
58 lines (39 loc) · 1.7 KB
/
CheckoutStepTwo.java
File metadata and controls
58 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package saucedemo.pageobjects;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import static org.openqa.selenium.By.className;
import static org.openqa.selenium.By.id;
import static org.openqa.selenium.By.xpath;
public class CheckoutStepTwo extends Cart {
private final By labelPriceItemsTotal = className("summary_subtotal_label");
private final By labelPriceTax = className("summary_tax_label");
private final By labelPriceTotal = xpath("//div[@data-test='total-label']");
private final By labelPriceAllItemsValues = xpath("//*[@class='inventory_item_price']");
private final By buttonCancel = id("cancel");
private final By buttonFinish = id("finish");
public void clickCancelButton(){
clickOnButton(buttonCancel);
}
public void clickFinishButton(){
clickOnButton(buttonFinish);
}
public String getProductsTotalPrice(){
return (getTextFromField(labelPriceItemsTotal).substring(13));
}
public String getProductTaxPrice(){
return (getTextFromField(labelPriceTax).substring(6));
}
public String getProductFinalTotalPrice(){
return (getTextFromField(labelPriceTotal).substring(8));
}
public int getNumberOfProductsInCheckout(){
return driver.findElements(labelPriceAllItemsValues).size();
}
public double getPriceForItem(int index){
String asString = String.valueOf(labelPriceAllItemsValues).substring(10);
String asStringModified = "("+ asString + ")[%d]";
By asBy = By.xpath(String.format(asStringModified, index + 1));
WebElement webElement = driver.findElement(asBy);
return Double.parseDouble(webElement.getText().substring(1));
}
}