package com.mridul.framework.selenium.modals; import com.mridul.framework.selenium.pages.HomePage; import com.mridul.framework.selenium.pages.AbstractPage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindAll; import org.openqa.selenium.support.FindBy; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.ThreadLocalRandom; /** * Created by Mridul on 3/12/2016. */ public final class ReportAnIssueModal extends AbstractModal { //anchor elements @FindBy(id = "myModalLabel") private WebElement lbl_ReportAnIssue_Anchor; @FindBy(id = "submit_button") private WebElement btn_Submit_Anchor; //Modal elements @FindBy(id = "favorite_icon") private WebElement icon_Favorite; @FindBy(css = "span[class='glyphicon-remove-circle']") private WebElement icon_Close; @FindBy(id = "modaliframe") private WebElement iframe_modaliframe; @FindBy(css = "div[class='navbar-right'] > div > button") private WebElement btn_ExpandCollapse; //@FindBy(xpath = "//*div[@class='input-group']/input[starts-with(@id,'sys_display.IO:')][1]") //@FindBy(xpath = "//*div[@class='input-group']/input[1]") @FindBy(xpath = "//*[@id='sys_display.IO:5c9dc8300f9521008783918172050e2c']") private WebElement txtfld_RequestedBy; //@FindBy(xpath = "//*div[@class='input-group']/input[starts-with(@id,'sys_display.IO:')][2]") //@FindBy(xpath = "//*div[@class='input-group']/input[2]") @FindBy(xpath = "//*[@id='sys_display.IO:dfedc8300f9521008783918172050e48']") private WebElement txtfld_RequestedFor; //@FindBy(xpath = "//*input[starts-with(@id,'IO:')][1]") //@FindBy(xpath = "//*div[@class='input_controls']/input[2]") @FindBy(xpath = "//*[@id='IO:a6c626970f55a10040a7945f62050e98']") private WebElement txtfld_CallBackNumber; @FindBy(name = "checkbox_container") private WebElement chkbox_UnlistedUser; @FindBy(xpath = "//*[@id='IO:84c9eed30f55a10040a7945f62050e83']") private WebElement txtfld_UnlistedContactName; @FindBy(xpath = "//*[@id='IO:201aaa970f55a10040a7945f62050e9d']") private WebElement txtfld_UnlistedContactEmail; @FindBy(xpath = "//*[@id='IO:d4665dce0f9806008783918172050e13']") private WebElement txtfld_Other; //@FindBy(xpath = "//*select[starts-with(@id,'IO:')][1]") @FindBy(xpath = "//*[@id='IO:081b7d970f3b310040a7945f62050eb2']") private WebElement selfld_BusinessUrgency; //@FindBy(xpath = "//*select[starts-with(@id,'IO:')][2]") @FindBy(xpath = "//*[@id='IO:c56c79d70f3b310040a7945f62050ead']") private WebElement selfld_BusinessImpact; //@FindBy(xpath = "//*select[starts-with(@id,'IO:')][3]") @FindBy(xpath = "//*[@id='IO:48ec3dd70f3b310040a7945f62050ef5']") private WebElement selfld_TypeOfIssue; @FindAll({ @FindBy(xpath = "//*[@id='IO:f32d391b0f3b310040a7945f62050e4a']"), @FindBy(xpath = "//*[@id='IO:b25d7dd70f3b310040a7945f62050ef0']"), @FindBy(xpath = "//*[@id='IO:a032194e0f9806008783918172050e1b']") }) private WebElement selfld_Category; //@FindBy(xpath = "//*textarea[starts-with(@id,'IO:')][3]") @FindBy(xpath = "//*[@id='IO:bd6db91b0f3b310040a7945f62050e0c']") private WebElement txtarea_DescribeIssue; @FindBy(xpath = "/html/body/center/div/img") private WebElement img_GreenChecMark; //instance variables private TypeOfIssue typeOfIssue; private enum TypeOfIssue { HARDWARE(1, 12), SOFTWARE(2, 16), SOS(3, 7); private int index; private int categorySize; private static final List<TypeOfIssue> VALUES = Collections.unmodifiableList(Arrays.asList(values())); private static final int SIZE = VALUES.size(); private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current(); TypeOfIssue(int index, int categorySize) { this.index = index; this.categorySize = categorySize; } int getIndex() { return index; } int getCategorySize() { return categorySize; } public static TypeOfIssue getRandomValue() { return VALUES.get(RANDOM.nextInt(SIZE)); } } public ReportAnIssueModal(WebDriver driver, AbstractPage parentPage) { super(driver, parentPage); super.switchToIFrame(iframe_modaliframe); } @Override protected List<WebElement> registerAnchors() { return Arrays.asList(lbl_ReportAnIssue_Anchor, btn_Submit_Anchor); } @Override public ReportAnIssueModal and() { return this; } @Override public ReportAnIssueModal then() { return this; } public ReportAnIssueModal fillingRequestorInformationForm() { return this; } public ReportAnIssueModal fillInRequestedBy(String text) { super.populateTextField(txtfld_RequestedBy, text); return this; } //private getters and setters private TypeOfIssue getTypeOfIssue() { return typeOfIssue; } private void setTypeOfIssue(TypeOfIssue typeOfIssue) { this.typeOfIssue = typeOfIssue; } public ReportAnIssueModal fillInRequestedFor(String text) { super.populateTextField(txtfld_RequestedFor, text); return this; } public ReportAnIssueModal fillInCallbackNumber(String text) { super.populateTextField(txtfld_CallBackNumber, text); return this; } public ReportAnIssueModal checkUnlistedUser() { super.checkOnCheckBox(chkbox_UnlistedUser); return this; } public ReportAnIssueModal fillInUnlistedContactName(String text) { super.populateTextField(txtfld_UnlistedContactName, text); return this; } public ReportAnIssueModal fillInUnlistedContactEmail(String text) { super.populateTextField(txtfld_UnlistedContactEmail, text); return this; } public ReportAnIssueModal uncheckUnlistedUser() { super.unCheckOnCheckBox(chkbox_UnlistedUser); return this; } public ReportAnIssueModal selectBusinessUrgency(String text) { super.selectOptionByText(selfld_BusinessUrgency, text); return this; } public ReportAnIssueModal selectAnyBusinessUrgency() { //super.selectOptionByIndex(selfld_BusinessUrgency, 3); super.selectOptionByRandomValue(selfld_BusinessUrgency); return this; } public ReportAnIssueModal selectBusinessImpact(String text) { super.selectOptionByText(selfld_BusinessImpact, text); return this; } public ReportAnIssueModal selectAnyBusinessImpact() { //super.selectOptionByIndex(selfld_BusinessImpact, 3); super.selectOptionByRandomValue(selfld_BusinessImpact); return this; } public ReportAnIssueModal selectTypeOfIssue(String text) { super.selectOptionByText(selfld_TypeOfIssue, text); return this; } public ReportAnIssueModal selectAnyTypeOfIssue() { /* TypeOfIssue typeOfIssue = TypeOfIssue.getRandomValue(); this.setTypeOfIssue(typeOfIssue); //Type of issue has index as value unlike other elements super.selectOptionByRandomIndex(selfld_TypeOfIssue, typeOfIssue.getIndex());*/ super.selectOptionByRandomValue(selfld_TypeOfIssue); return this; } public ReportAnIssueModal selectCategory(String text) { super.selectOptionByText(selfld_Category, text); return this; } public ReportAnIssueModal selectAnyCategory() { /* super.selectOptionByRandomIndex(selfld_Category, this.getTypeOfIssue().getCategorySize());*/ super.selectOptionByRandomValue(selfld_Category); return this; } public ReportAnIssueModal fillInPleaseDescribeYourIssue(String text) { super.populateTextField(txtarea_DescribeIssue, text); //Category has index as value unlike other elements return this; } public ReportAnIssueModal clickOnSubmitButton() { super.clickOnButton(btn_Submit_Anchor); return this; } public HomePage clickOnCloseButton() { super.clickOnButton(img_GreenChecMark); return (HomePage) super.getParentPage(); } }
Friday, August 5, 2016
ReportAnIssueModal
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment