tis-2017/Semenova/src/test/java/Pages/CalculatorPage.java
2018-03-17 15:08:55 +04:00

131 lines
4.0 KiB
Java

package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
public class CalculatorPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".tbl_box #fromDate")
private WebElement fromDateInput;
@FindBy(css = ".tbl_box #toDate")
private WebElement toDateInput;
@FindBy(css = ".tbl_box #amountOfShares")
private WebElement amountInput;
@FindBy(css = ".tbl_box table tr:nth-child(8) input")
private WebElement calculateBtn;
@FindBy(css = ".result tr")
private List<WebElement> tableElements;
@FindBy(css = ".result tr:nth-child(11) td:nth-child(2)")
private WebElement startPrice;
@FindBy(css = ".result tr:nth-child(12) td:nth-child(2)")
private WebElement endPrice;
@FindBy(css = ".result tr:nth-child(13) td:nth-child(3)")
private WebElement reInvPrice;
@FindBy(css = ".result tr:nth-child(3) td:nth-child(2)")
private WebElement changePrice;
@FindBy(css = ".result tr:nth-child(7) td:nth-child(2)")
private WebElement changePriceRe;
@FindBy(css = ".result tr:nth-child(1) span")
private WebElement income;
@FindBy(id = "ruCalc")
private WebElement ruCalcFrame;
@FindBy(name = "chart")
private WebElement chartFrame;
public CalculatorPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void switchToCalcFrame(){
wait.until(ExpectedConditions.visibilityOfAllElements(ruCalcFrame));
driver.switchTo().frame(ruCalcFrame);
driver.switchTo().frame(chartFrame);
}
public void clickCalcBtn(){
calculateBtn.click();
}
public double getStartPrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(startPrice));
String tmp = startPrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf(" ")+1);
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getEndPrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(endPrice));
String tmp = endPrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf(" ")+1);
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getReInvPrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(reInvPrice));
String tmp = reInvPrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf(" ")+1);
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getChangePrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(changePrice));
String tmp = changePrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf("%"));
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getChangePriceRe(){
wait.until(ExpectedConditions.visibilityOfAllElements(changePriceRe));
String tmp = changePriceRe.getText();
tmp = tmp.substring(0,tmp.lastIndexOf("%"));
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getIncome(){
wait.until(ExpectedConditions.visibilityOfAllElements(income));
String tmp = income.getText();
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public void insertFromDate(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(fromDateInput));
fromDateInput.clear();
fromDateInput.sendKeys(text);
}
public void insertToDate(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(toDateInput));
toDateInput.clear();
toDateInput.sendKeys(text);
}
public void insertAmount(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(amountInput));
amountInput.clear();
amountInput.sendKeys(text);
}
}