How to use getCurrentPage method of com.paypal.selion.platform.html.AbstractContainer class

Best SeLion code snippet using com.paypal.selion.platform.html.AbstractContainer.getCurrentPage

Source:AbstractContainer.java Github

copy

Full Screen

...71 * 72 * sampleContainer.getMyTextField().type("Hi! Welcome");73 * 74 * <b><h2>Note:</b> A stand alone constructor does not have a parent by default.75 * Hence access to method getCurrentPage() will resolve to null.76 * </pre>77 * 78 * </td>79 * </tr>80 * <tr>81 * <td>82 * <b><i>A container inside a page</i></b>83 * 84 * <pre>85 * public class MyPage extends BasePageImpl {86 * private MyContainer myContainer;87 * 88 * public MyPage() {89 * super.initPage(PAGE_DOMAIN, CLASS_NAME);90 * }91 * 92 * public MyPage(String siteLocale) {93 * super.initPage(PAGE_DOMAIN, CLASS_NAME, siteLocale);94 * }95 * 96 * public MyPage getPage() {97 * if (!isInitialized()) {98 * loadObjectMap();99 * initializeHtmlObjects(this, this.objectMap);100 * }101 * return this;102 * }103 * 104 * public MyContainer getMyContainer() {105 * return getPage().myContainer;106 * }107 * 108 * public MyContainer getMyContainer(int index) {109 * getPage().myContainer.setIndex(index);110 * return myContainer;111 * }112 * 113 * <b> Container creation </b>114 * class MyContainer extends AbstractContainer {115 * public MyContainer(String locator) {116 * super(locator);117 * }118 * 119 * public MyContainer(String locator, String controlName) {120 * super(locator, controlName);121 * }122 * 123 * private TextField myTextField;124 * 125 * public TextField getMyTextField() {126 * return myTextField;127 * }128 * }129 * }130 * </pre>131 * 132 * </td>133 * <td>134 * 135 * <pre>136 * <u>To retrieve a child element from a container at a specified index:</u>137 * 138 * <pre>139 * MyPage myPage = new MyPage();140 * myPage.getMyContainer(1).getMyTextField();141 * </pre>142 * 143 * <u>To retrieve a child element from a container at the last specified index or 0 if no index has ever been144 * specified:</u>145 * 146 * <pre>147 * MyPage myPage = new MyPage();148 * myPage.getMyContainer().getMyTextField();149 * </pre>150 * 151 * <u>To retrieve the number of containers found on the page:</u>152 * 153 * <pre>154 * MyPage myPage = new MyPage();155 * myPage.getMyContainer().size();156 * 157 * <h2><b>Note:</b> In this use case, access to getCurrentPage will resolve to the page object where the container is present.158 * In this case it is the MyPage.159 * 160 * </pre>161 * 162 * </td>163 * </tr>164 * </table>165 * </p>166 */167public abstract class AbstractContainer extends AbstractElement implements ParentTraits {168 private int index;169 protected Map<String, String> containerElements;170 /**171 * Constructs a Container with locator.172 * 173 * @param locator174 * A String that represents the means to locate this element (could be id/name/xpath/css locator).175 * 176 */177 public AbstractContainer(String locator) {178 this(locator, null);179 }180 /**181 * Constructs a Container with locator and controlName.182 * 183 * @param locator184 * A String that represents the means to locate this element (could be id/name/xpath/css locator).185 * @param controlName186 * The control name used for logging.187 */188 public AbstractContainer(String locator, String controlName) {189 this(locator, controlName, null);190 }191 /**192 * Constructs a {@link Container} with locator, controlName and a parent193 * 194 * @param locator195 * A String that represents the means to locate this element (could be id/name/xpath/css locator).196 * @param controlName197 * The control name used for logging.198 * @param parent199 * A {@link ParentTraits} object that represents the parent element for this element.200 */201 public AbstractContainer(String locator, String controlName, ParentTraits parent) {202 super(locator, controlName, parent);203 }204 205 /**206 * Constructs a {@link Container} with locator, controlName, parent and containerElements207 * 208 * @param locator209 * A String that represents the means to locate this element (could be id/name/xpath/css locator).210 * @param controlName211 * The control name used for logging.212 * @param parent213 * A {@link ParentTraits} object that represents the parent element for this element.214 * @param containerElements215 * A {@link Map} containing the locators for elements inside this container.216 */217 public AbstractContainer(String locator, String controlName, ParentTraits parent,Map<String,String> containerElements){218 super(locator,controlName,parent);219 this.containerElements = containerElements; 220 }221 /**222 * Sets the index at which the element will be returned when {@link #getElement()} is called.223 * 224 * @param index225 * The index at which the element will be returned when getElement() is called.226 */227 public void setIndex(int index) {228 this.index = index;229 }230 /**231 * Used to call {@link HtmlElementUtils#locateElements(String) locateElements} and returns the element at current232 * index (which was set via {@link #setIndex(int)})233 * 234 * @return The web element found by locator at current index235 */236 @Override237 public RemoteWebElement getElement() {238 /*239 * Note: Rationale behind throwing ParentNotFoundException here.240 * 241 * Container's being a parent type is searched using a locator. When the locator is invalid it will be better to242 * throw ParentNotFoundException to the user so that it clearly indicates its the container.243 */244 List<WebElement> elements = null;245 try {246 if (getParent() != null) {247 elements = getParent().locateChildElements(getLocator());248 } else {249 // Its a case where there is a stand alone container and no parent250 elements = HtmlElementUtils.locateElements(getLocator());251 }252 } catch (NoSuchElementException n) {253 throw new ParentNotFoundException("Could not find any parent with the locator " + getLocator(), n);254 }255 if (index <= elements.size()) {256 return (RemoteWebElement) elements.get(index);257 }258 throw new NoSuchElementException("Cannot find Element With index :{" + index + "} in Container"259 + this.getClass().getSimpleName());260 }261 /**262 * Returns the number of containers found on the page.263 * 264 * @return the number of containers found on the page265 */266 public int size() {267 int size = 0;268 try {269 if (getParent() != null) {270 size = getParent().locateChildElements(getLocator()).size();271 } else {272 size = HtmlElementUtils.locateElements(getLocator()).size();273 }274 } catch (NoSuchElementException e) { // NOSONAR275 // do nothing, let size be returned as 0276 }277 return size;278 }279 /**280 * Sets the container index and searches for the descendant element using the child locator.281 * 282 * @param index283 * index of the container element to search on284 * @param childLocator285 * locator of the child element within the container286 * @return child WebElement found using child locator at the indexed container287 */288 public WebElement locateElement(int index, String childLocator) {289 if (index < 0) {290 throw new IllegalArgumentException("index cannot be a negative value");291 }292 setIndex(index);293 WebElement locatedElement = null;294 if (getParent() != null) {295 locatedElement = getParent().locateChildElement(childLocator);296 } else {297 locatedElement = HtmlElementUtils.locateElement(childLocator, this);298 }299 return locatedElement;300 }301 public List<WebElement> locateChildElements(String locator) {302 HtmlElementUtils.isValidXpath(locator);303 By locatorBy = HtmlElementUtils.resolveByType(locator);304 return this.getElement().findElements(locatorBy);305 }306 public RemoteWebElement locateChildElement(String locator) {307 HtmlElementUtils.isValidXpath(locator);308 By locatorBy = HtmlElementUtils.resolveByType(locator);309 return (RemoteWebElement) this.getElement().findElement(locatorBy);310 }311 public BasicPageImpl getCurrentPage() {312 return (BasicPageImpl) this.getParent();313 }314}...

Full Screen

Full Screen

getCurrentPage

Using AI Code Generation

copy

Full Screen

1import org.testng.annotations.Test;2import com.paypal.selion.platform.html.AbstractContainer;3import com.paypal.selion.platform.html.Page;4import com.paypal.selion.platform.html.PageFactory;5public class AbstractContainerTest {6 public void getCurrentPageTest() {7 AbstractContainer container = new AbstractContainer(page.getWebPage().getHtmlElement("id=footer"));8 Page currentPage = container.getCurrentPage();9 System.out.println(currentPage);10 }11}

Full Screen

Full Screen

getCurrentPage

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.platform.html.support.events;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import com.paypal.selion.platform.html.AbstractElement;5import com.paypal.selion.platform.html.support.HtmlElementUtils;6 * This class is used to represent a click event on a web element. This class is used by the {@link HtmlElementUtils} class7public class ClickEvent extends AbstractElementEvent {8 public ClickEvent(AbstractElement element) {9 super(element);10 }11 public void fireEvent(WebDriver driver, WebElement webElement) {12 webElement.click();13 }14}15package com.paypal.selion.platform.html.support.events;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.WebElement;18import com.paypal.selion.platform.html.AbstractElement;19import com.paypal.selion.platform.html.support.HtmlElementUtils;20public class DoubleClickEvent extends AbstractElementEvent {21 public DoubleClickEvent(AbstractElement element) {22 super(element);23 }24 public void fireEvent(WebDriver driver, WebElement webElement) {25 HtmlElementUtils.doubleClick(driver, webElement);26 }27}28package com.paypal.selion.platform.html.support.events;29import org.openqa.selenium.WebDriver;30import org.openqa.selenium.WebElement;31import com.paypal.selion.platform.html.AbstractElement;32import com.paypal.selion.platform.html.support.HtmlElementUtils;33 * {@link HtmlElementUtils

Full Screen

Full Screen

getCurrentPage

Using AI Code Generation

copy

Full Screen

1PageObject currentPage = AbstractContainer.getCurrentPage();2PageObject activePage = AbstractContainer.getActivePage();3PageObject activePage = AbstractContainer.getActivePage();4PageObject currentPage = AbstractContainer.getCurrentPage();5PageObject activePage = AbstractContainer.getActivePage();6PageObject currentPage = AbstractContainer.getCurrentPage();7PageObject activePage = AbstractContainer.getActivePage();8PageObject currentPage = AbstractContainer.getCurrentPage();9PageObject activePage = AbstractContainer.getActivePage();10PageObject currentPage = AbstractContainer.getCurrentPage();11PageObject activePage = AbstractContainer.getActivePage();12PageObject currentPage = AbstractContainer.getCurrentPage();13PageObject activePage = AbstractContainer.getActivePage();14PageObject currentPage = AbstractContainer.getCurrentPage();15PageObject activePage = AbstractContainer.getActivePage();16PageObject currentPage = AbstractContainer.getCurrentPage();

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.

Run SeLion automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful