How to use verifyElementByAction method of com.paypal.selion.testcomponents.BasicPageImpl class

Best SeLion code snippet using com.paypal.selion.testcomponents.BasicPageImpl.verifyElementByAction

Source:BasicPageImpl.java Github

copy

Full Screen

...108 if (indexOf != -1) {109 action = elementName.substring(indexOf + 1, elementName.length());110 elementName = elementName.substring(0, indexOf);111 }112 verifyElementByAction(elementName, action, isInvertValidationLogic);113 }114 }115 }116 /**117 * Get the AbstractElement by the key that is defined in the PageYAML files.118 *119 * @param elementName120 * The element name121 * @return instance of {@link AbstractElement}122 */123 private AbstractElement getAbstractElementThroughReflection(String elementName) {124 Field field = null;125 Class<?> currentClass = getClass();126 do {127 try {128 field = currentClass.getDeclaredField(elementName);129 field.setAccessible(true);130 return (AbstractElement) currentClass.getMethod("get" + StringUtils.capitalize(field.getName()))131 .invoke(this);132 } catch (Exception e) {133 // NOSONAR134 }135 } while ((currentClass = currentClass.getSuperclass()) != null);136 throw new UndefinedElementException("Element with name " + elementName + " doesn't exist.");137 }138 /**139 * Verify if the element is available based on a certain action140 *141 * @param elementName142 * element to perform verification action on143 * @param action144 * verification action to perform145 */146 private void verifyElementByAction(String elementName, String action, boolean isInvertValidationLogic) {147 AbstractElement element = getAbstractElementThroughReflection(elementName);148 boolean present = element.isElementPresent();149 switch (action) {150 case "isVisible":151 if (isInvertValidationLogic ? present && element.isVisible() : !present || !element.isVisible()) {152 throw new PageValidationException(getClass().getSimpleName() + " isn't loaded in the browser, "153 + elementName + " with locator " + element.getLocator() + " is" +154 (isInvertValidationLogic ? " visible.": " not visible."));155 }156 break;157 case "isEnabled":158 if (isInvertValidationLogic ? present && element.isEnabled() : !present || !element.isEnabled()) {159 throw new PageValidationException(getClass().getSimpleName() + " isn't loaded in the browser, "160 + elementName + " with locator " + element.getLocator() + " is" +161 (isInvertValidationLogic ? " enabled.": " not enabled."));162 }163 break;164 case "isPresent":165 default:166 if (isInvertValidationLogic ? present : !present) {167 throw new PageValidationException(getClass().getSimpleName() + " isn't loaded in the browser, "168 + elementName + " with locator " + element.getLocator() + " is" +169 (isInvertValidationLogic ? " present.": " not present."));170 }171 break;172 }173 }174 @Override175 public boolean isPageValidated() {176 try {177 checkIfLoaded();178 validatePage();179 return true;180 } catch (Exception ex) {181 return false;182 }183 }184 @Override185 public void checkIfLoaded() {186 getObjectMap();187 for (String elementName : getPageLoadingValidators()) {188 // We can set the action we want to check for, by putting a dot at the end of the elementName.189 // Following by isPresent, isVisible or isEnabled, default behaviour isPresent190 String action = "";191 int indexOf = elementName.indexOf(".");192 if (indexOf != -1) {193 action = elementName.substring(indexOf + 1, elementName.length());194 elementName = elementName.substring(0, indexOf);195 }196 // Validation logic is inverted because page is considered fully loaded when no loading validators are197 // present, visible, or enabled in the page.198 verifyElementByAction(elementName, action, true);199 }200 }201 @Override202 public boolean isPageLoaded() {203 try {204 checkIfLoaded();205 return true;206 } catch (Exception ex) {207 return false;208 }209 }210}...

Full Screen

Full Screen

verifyElementByAction

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.platform.grid.Grid;2import com.paypal.selion.platform.utilities.WebDriverWaitUtils;3import com.paypal.selion.testcomponents.BasicPageImpl;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.testng.annotations.Test;7public class BasicPageImplTests {8 public void testVerifyElementByAction() throws Exception {9 WebDriverWaitUtils.waitUntilElementIsPresent(By.name("q"));10 WebElement searchBox = Grid.driver().findElement(By.name("q"));11 BasicPageImpl.verifyElementByAction(searchBox, "isPresent");12 BasicPageImpl.verifyElementByAction(searchBox, "isVisible");13 BasicPageImpl.verifyElementByAction(searchBox, "isNotVisible", false);14 BasicPageImpl.verifyElementByAction(searchBox, "isEditable");15 BasicPageImpl.verifyElementByAction(searchBox, "isNotEditable", false);16 BasicPageImpl.verifyElementByAction(searchBox, "isSelected", false);17 BasicPageImpl.verifyElementByAction(searchBox, "isNotSelected");18 BasicPageImpl.verifyElementByAction(searchBox, "isDisabled", false);19 BasicPageImpl.verifyElementByAction(searchBox, "isNotDisabled");20 }21}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful