|
| 1 | +package pages; |
| 2 | + |
| 3 | +import org.openqa.selenium.By; |
| 4 | +import org.openqa.selenium.WebDriver; |
| 5 | +import org.openqa.selenium.WebElement; |
| 6 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 7 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | + |
| 11 | +public class InvoiceGeneratorPage { |
| 12 | + |
| 13 | + private WebDriver driver; |
| 14 | + WebDriverWait wait; |
| 15 | + |
| 16 | + //HEADER |
| 17 | + private By invoiceTitleField = By.id("invoice-title"); |
| 18 | + private By logoInput = By.xpath("//div[contains(@class, 'invoice-logo')]/descendant::input"); |
| 19 | + |
| 20 | + //FROM FIELDS |
| 21 | + private By fromNameField = By.id("invoice-company-name"); |
| 22 | + private By fromEmailField = By.id("invoice-company-email"); |
| 23 | + private By fromAddressField = By.id("invoice-company-address1"); |
| 24 | + private By fromCityStateField = By.id("invoice-company-address2"); |
| 25 | + private By fromZipCodeField = By.id("invoice-company-address3"); |
| 26 | + private By fromPhoneField = By.id("invoice-company-phone"); |
| 27 | + private By fromBusinessPhoneField = By.id("invoice-company-business-number"); |
| 28 | + |
| 29 | + //TO FIELDS |
| 30 | + private By toNameField = By.id("invoice-client-name"); |
| 31 | + private By toEmailField = By.id("invoice-client-email"); |
| 32 | + private By toAddressField = By.id("invoice-client-address1"); |
| 33 | + private By toPhoneField = By.id("invoice-client-phone"); |
| 34 | + |
| 35 | + |
| 36 | + private By invoiceNumberField = By.id("invoice-number"); |
| 37 | + |
| 38 | + //ITEMS |
| 39 | + private String itemRow_Format = "//tr[contains(@class, 'item-row-%d')]"; |
| 40 | + private By itemDescription_Child = By.id("invoice-item-code"); |
| 41 | + private By itemPrice_Child = By.xpath("td[contains(@class, 'item-row-rate')]/descendant::input"); |
| 42 | + private By itemQuantity_Child = By.xpath("td[contains(@class, 'item-row-quantity')]/descendant::input"); |
| 43 | + private By itemDetails_Child = By.tagName("textarea"); |
| 44 | + private By addItemButton = By.id("invoice-item-add"); |
| 45 | + |
| 46 | + private By notesArea = By.id("invoice-notes"); |
| 47 | + private By getLinkButton = By.xpath("//span[text()='Get Link']/parent::button"); |
| 48 | + |
| 49 | + private By colorSelectList = By.className("color-select-option"); |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + public InvoiceGeneratorPage(WebDriver driver){ |
| 54 | + this.driver = driver; |
| 55 | + wait = new WebDriverWait(driver, 5); |
| 56 | + } |
| 57 | + |
| 58 | + public void setInvoiceTitle(String title){ |
| 59 | + WebElement field = driver.findElement(invoiceTitleField); |
| 60 | + wait.until(ExpectedConditions.elementToBeClickable(field)); |
| 61 | + field.clear(); |
| 62 | + field.sendKeys(title); |
| 63 | + } |
| 64 | + |
| 65 | + public void setLogo(File imgFile){ |
| 66 | + driver.findElement(logoInput).sendKeys(imgFile.getAbsolutePath()); |
| 67 | + } |
| 68 | + |
| 69 | + public void setFromName(String name){ |
| 70 | + driver.findElement(fromNameField).sendKeys(name); |
| 71 | + } |
| 72 | + |
| 73 | + public void setFromEmail(String email){ |
| 74 | + driver.findElement(fromEmailField).sendKeys(email); |
| 75 | + } |
| 76 | + |
| 77 | + public void setFromAddress(String address){ |
| 78 | + driver.findElement(fromAddressField).sendKeys(address); |
| 79 | + } |
| 80 | + |
| 81 | + public void setFromCityState(String cityAndState){ |
| 82 | + driver.findElement(fromCityStateField).sendKeys(cityAndState); |
| 83 | + } |
| 84 | + |
| 85 | + public void setFromZipCode(String zipCode){ |
| 86 | + driver.findElement(fromZipCodeField).sendKeys(zipCode); |
| 87 | + } |
| 88 | + |
| 89 | + public void setFromPhone(String phoneNumber){ |
| 90 | + driver.findElement(fromPhoneField).sendKeys(phoneNumber); |
| 91 | + } |
| 92 | + |
| 93 | + public void setFromBusinessPhone(String phoneNumber){ |
| 94 | + driver.findElement(fromBusinessPhoneField).sendKeys(phoneNumber); |
| 95 | + } |
| 96 | + |
| 97 | + public void setToName(String name){ |
| 98 | + driver.findElement(toNameField).sendKeys(name); |
| 99 | + } |
| 100 | + |
| 101 | + public void setToEmail(String email){ |
| 102 | + driver.findElement(toEmailField).sendKeys(email); |
| 103 | + } |
| 104 | + |
| 105 | + public void setToAddress(String address){ |
| 106 | + driver.findElement(toAddressField).sendKeys(address); |
| 107 | + } |
| 108 | + |
| 109 | + public void setToPhone(String phoneNumber){ |
| 110 | + driver.findElement(toPhoneField).sendKeys(phoneNumber); |
| 111 | + } |
| 112 | + |
| 113 | + public void setInvoiceNumber(String invoiceNumber){ |
| 114 | + WebElement field = driver.findElement(invoiceNumberField); |
| 115 | + field.clear(); |
| 116 | + field.sendKeys(invoiceNumber); |
| 117 | + } |
| 118 | + |
| 119 | + public void setItemDescription(int itemIndex, String description){ |
| 120 | + getItemRow(itemIndex).findElement(itemDescription_Child).sendKeys(description); |
| 121 | + } |
| 122 | + |
| 123 | + public void setItemPrice(int itemIndex, String price){ |
| 124 | + getItemRow(itemIndex).findElement(itemPrice_Child).sendKeys(price); |
| 125 | + } |
| 126 | + |
| 127 | + public void setItemQuantity(int itemIndex, String quantity){ |
| 128 | + getItemRow(itemIndex).findElement(itemQuantity_Child).sendKeys(quantity); |
| 129 | + } |
| 130 | + |
| 131 | + public void setItemAdditionalDetails(int itemIndex, String details){ |
| 132 | + getItemRow(itemIndex).findElement(itemDetails_Child).sendKeys(details); |
| 133 | + } |
| 134 | + |
| 135 | + public void clickToAddNewItem(){ |
| 136 | + WebElement button = driver.findElement(addItemButton); |
| 137 | + wait.until(ExpectedConditions.elementToBeClickable(button)); |
| 138 | + button.click(); |
| 139 | + } |
| 140 | + |
| 141 | + public void selectColor(int index){ |
| 142 | + driver.findElements(colorSelectList).get(index).click(); |
| 143 | + } |
| 144 | + |
| 145 | + public InvoicePreviewPage clickGetLink(){ |
| 146 | + String invoiceWindowTitle = String.format("Invoice %s - %s", |
| 147 | + driver.findElement(invoiceNumberField).getAttribute("value"), |
| 148 | + driver.findElement(fromNameField).getAttribute("value")); |
| 149 | + |
| 150 | + driver.findElement(getLinkButton).click(); |
| 151 | + return new InvoicePreviewPage(driver, invoiceWindowTitle); |
| 152 | + } |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + private WebElement getItemRow(int index){ |
| 157 | + String xpath = String.format(itemRow_Format, index); |
| 158 | + return driver.findElement(By.xpath(xpath)); |
| 159 | + } |
| 160 | + |
| 161 | + |
| 162 | +} |
0 commit comments