/** * 1. map elements of interest to their name * 2. reload elements from the page every time `map` is called * * E.g., Say ELEMENT_LOCATORS=id * and <input id="username" type="text"></input> * then nameElementMap will contain "username" => WebElement */ @Override protected void map(AbstractPage p) { getBys(); List<WebElement> elements = new ArrayList<WebElement>(); for (By by : bys) { elements.addAll(driver.findElements(by)); } PageFactory.initElements(driver, this); String[] tokens = locators.split(","); for(WebElement w: elements) { for (String s : tokens) { try{ String attr = w.getAttribute(s);//throws StaleElementReferenceException if (attr != null) { nameElementMap.put(attr, w); } }catch(StaleElementReferenceException se){ //ignoring elements which have become stale because //a stale object shouldn't have to be referenced //by an automation script } } } }
public AbstractPage addPageObject(AbstractPage p) { String url = p.forUrl(); if(!mapper.containsKey(url)){ mapper.put(url, p); String currentUrl = null; try{ String currUrl = driver.getCurrentUrl(); URI url2 = new URI(currUrl); String path = url2.getPath(); currentUrl = currUrl.substring(0, currUrl.indexOf(path)); }catch (URISyntaxException e) { e.printStackTrace(); } catch(NullPointerException npe){ currentUrl = baseUrl; } p.setBaseUrl(baseUrl.equals(currentUrl) ? baseUrl: currentUrl); PageFactory.initElements(driver, p); } return mapper.get(url); }
public ApplicationPageStructuralFactory(WebDriver driver, TodoMVCSite todoMVCSite) { PageFactory.initElements(driver, this); this.driver = driver; this.todoMVCSite = todoMVCSite; wait = new WebDriverWait(driver,10); // move the mouse out of the way so it // doesn't interfere with the test try { new Robot().mouseMove(0,0); } catch (AWTException e) { e.printStackTrace(); } }
@Test public void testAddAndRemoveWordLabel() { AudioListPage audioListPage = PageFactory.initElements(driver, AudioListPage.class); if (audioListPage.getListCount() > 0) { audioListPage.clickRandomEditLink(); AudioEditPage audioEditPage = PageFactory.initElements(driver, AudioEditPage.class); audioEditPage.addWordLabel("apple"); // Refresh current page driver.navigate().refresh(); PageFactory.initElements(driver, AudioEditPage.class); audioEditPage.removeWordLabel("apple"); } }
@Test public void testEdit() { VideoListPage videoListPage = PageFactory.initElements(driver, VideoListPage.class); if (videoListPage.getListCount() > 0) { videoListPage.clickRandomEditLink(); VideoEditPage videoEditPage = PageFactory.initElements(driver, VideoEditPage.class); videoEditPage.submitForm(); // TODO // PageFactory.initElements(driver, VideoListPage.class); } }
public RiotSettingsPageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); try { waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"im.vector.alpha:id/vector_settings_page", true, 10); } catch (InterruptedException e) { e.printStackTrace(); } }
@BeforeMethod public void showDialog() throws Throwable { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame = new JFrame(JTreeDynamicTreeTest.class.getSimpleName()); frame.setName("frame-" + JTreeDynamicTreeTest.class.getSimpleName()); frame.getContentPane().add(new DynamicTreeDemo(), BorderLayout.CENTER); frame.pack(); frame.setAlwaysOnTop(true); frame.setVisible(true); } }); driver = new JavaDriver(); page = PageFactory.initElements(driver, DynamicTreePage.class); }
private ElementsContainer initElementsContainer(Class<?> type, SelenideElement self) throws Exception { Constructor<?> constructor = type.getDeclaredConstructor(); constructor.setAccessible(true); ElementsContainer result = (ElementsContainer) constructor.newInstance(); PageFactory.initElements(new SelenideFieldDecorator(self), result); result.setSelf(self); return result; }
@Override public void setUp() throws Exception { super.setUp(); loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class); loginPO.login("admin", "admin"); }
@Override public void setUp() throws Exception { super.setUp(); // Use the PageFactory to automatically initialize fields. loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class); }
@Override public void setUp() throws Exception { super.setUp(); messages = Messages.getInstance(Locale.getDefault()); loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class); loginPO.login("admin", "admin"); }
public PageBase(WebDriver driver) { if(driver == null) throw new IllegalArgumentException("Driver object is null"); PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), this); this.driver = driver; }
@Parameters({ "path" }) @BeforeClass public void testInit(String path) { // Load the page in the browser webDriver.get(websiteUrl + path); homepage = PageFactory.initElements(webDriver, HomePage.class); }
@Test public void testListNotEmpty() { ProjectListPage projectListPage = PageFactory.initElements(driver, ProjectListPage.class); Boolean isEmpty = projectListPage.checkIfListItemIsEmpty(); assertTrue(isEmpty); }
@Test public void testSubmitEmptyForm() { ApplicationListPage applicationListPage = PageFactory.initElements(driver, ApplicationListPage.class); applicationListPage.clickAddButton(); ApplicationCreatePage applicationCreatePage = PageFactory.initElements(driver, ApplicationCreatePage.class); applicationCreatePage.submitForm(); assertThat(applicationCreatePage.isErrorMessageDisplayed(), is(true)); }
/** * Define global elements here */ public GoogleBaseView(WebDriver driver, GenericDataObject data){ this.driver = driver; this.data = data; PageFactory.initElements(driver, this); }
@Inject public LoginAndCreateOnpremAccountPage( SeleniumWebDriver seleniumWebDriver, Loader loader, TestDashboardUrlProvider dashboardUrlProvider) { this.seleniumWebDriver = seleniumWebDriver; this.loader = loader; this.dashboardUrlProvider = dashboardUrlProvider; PageFactory.initElements(seleniumWebDriver, this); redrawTimeout = new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC); loadPageTimeout = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC); }
@Test public void testSubmitEmptyForm() { AllophoneListPage allophoneListPage = PageFactory.initElements(driver, AllophoneListPage.class); allophoneListPage.clickAddButton(); AllophoneCreatePage allophoneCreatePage = PageFactory.initElements(driver, AllophoneCreatePage.class); allophoneCreatePage.submitForm(); assertThat(allophoneCreatePage.isErrorMessageDisplayed(), is(true)); }
@Test public void testSubmitEmptyForm() { ImageListPage imageListPage = PageFactory.initElements(driver, ImageListPage.class); imageListPage.clickAddButton(); ImageCreatePage imageCreatePage = PageFactory.initElements(driver, ImageCreatePage.class); imageCreatePage.submitForm(); assertThat(imageCreatePage.isErrorMessageDisplayed(), is(true)); }
public <T extends BasePage> T link(String repositoryName, String licenseName, Class<T> page) { Select cla = new Select(claName); Select repositoriesSelect = new Select(repositories); if(StringUtils.hasText(repositoryName)) { repositoriesSelect.selectByVisibleText(repositoryName); } if(StringUtils.hasText(licenseName)) { cla.selectByVisibleText(licenseName); } submit.click(); return PageFactory.initElements(getDriver(), page); }
@Test public void testSubmitEmptyForm() { LetterListPage letterListPage = PageFactory.initElements(driver, LetterListPage.class); letterListPage.clickAddButton(); LetterCreatePage letterCreatePage = PageFactory.initElements(driver, LetterCreatePage.class); letterCreatePage.submitForm(); assertThat(letterCreatePage.isErrorMessageDisplayed(), is(true)); }
@Test public void testEdit() { LetterListPage letterListPage = PageFactory.initElements(driver, LetterListPage.class); if (letterListPage.getListCount() > 0) { letterListPage.clickRandomEditLink(); LetterEditPage letterEditPage = PageFactory.initElements(driver, LetterEditPage.class); letterEditPage.submitForm(); PageFactory.initElements(driver, LetterListPage.class); } }
@Test public void testEdit() { WordListPage wordListPage = PageFactory.initElements(driver, WordListPage.class); if (wordListPage.getListCount() > 0) { wordListPage.clickRandomEditLink(); WordEditPage wordEditPage = PageFactory.initElements(driver, WordEditPage.class); wordEditPage.submitForm(); PageFactory.initElements(driver, WordListPage.class); } }
@Test public void testSubmitEmptyForm() { WordListPage wordListPage = PageFactory.initElements(driver, WordListPage.class); wordListPage.clickAddButton(); WordCreatePage wordCreatePage = PageFactory.initElements(driver, WordCreatePage.class); wordCreatePage.submitForm(); assertThat(wordCreatePage.isErrorMessageDisplayed(), is(true)); }
@Test public void testSaveExistingAndReturnToList() { StoryBookListPage storyBookListPage = PageFactory.initElements(driver, StoryBookListPage.class); storyBookListPage.clickRandomEditLink(); StoryBookEditPage storyBookEditPage = PageFactory.initElements(driver, StoryBookEditPage.class); storyBookEditPage.submitForm(); PageFactory.initElements(driver, StoryBookListPage.class); }
@Test public void testHttp404() { driver.get(DomainHelper.getBaseUrl() + "/asdf"); ErrorHelper.verifyNoScriptOrMarkupError(driver); ErrorPage errorPage = PageFactory.initElements(driver, ErrorPage.class); assertTrue("The error page was not displayed", errorPage.isDisplayed()); assertTrue("Error code was not 404", errorPage.isCode404()); }
public RiotUnknownDevicesPageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); try { waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"android:id/parentPanel", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotNewChatPageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); try { waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"im.vector.alpha:id/room_creation_members_list_view", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotCallingPageObjects(AppiumDriver<MobileElement> myDriver){ PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); driver=(AndroidDriver<MobileElement>) myDriver; try { waitUntilDisplayed(driver,"im.vector.alpha:id/call_layout", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotVerifyDevicePageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); try { waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"im.vector.alpha:id/parentPanel", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotCameraPageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(driver), this); Thread.sleep(2000); try { waitUntilDisplayed(driver,"im.vector.alpha:id/medias_picker_preview_gallery_layout", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotCaptchaPageObject(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(driver), this); Thread.sleep(2000); try { waitUntilDisplayed(driver,"im.vector.alpha:id/account_creation_message", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotPeopleTabPageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException { super(myDriver); PageFactory.initElements(new AppiumFieldDecorator(driver), this); //if 'Riot permissions .... Allow Riot to access your contacts' pops up, close it. if(waitUntilDisplayed(driver, "//android.widget.TextView[@resource-id='android:id/alertTitle' and @text='Information']", true, 1)){ driver.findElementById("android:id/button1").click(); } Assert.assertTrue(waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"im.vector.alpha:id/fragment_container", true, 5),"PeoplePage tab isn't open."); }
public RiotLoginAndRegisterPageObjects(AppiumDriver<MobileElement> myDriver) { driver= myDriver; PageFactory.initElements(new AppiumFieldDecorator(driver), this); try { Assert.assertTrue(waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"im.vector.alpha:id/login_inputs_layout", true, 10), "Riot login/register page isn't opened"); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotIncomingCallPageObjects(AppiumDriver<MobileElement> myDriver){ PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); driver=(AndroidDriver<MobileElement>) myDriver; try { waitUntilDisplayed(driver,"android:id/content", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotContactPickerPageObjects(AppiumDriver<MobileElement> myDriver) throws InterruptedException{ driver=(AndroidDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); try { waitUntilDisplayed((AndroidDriver<MobileElement>) driver,"im.vector.alpha:id/decor_content_parent", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotNewChatPageObjects(AppiumDriver<MobileElement> myDriver) { driver= myDriver; PageFactory.initElements(new AppiumFieldDecorator(driver), this); try { waitUntilDisplayed((IOSDriver<MobileElement>) driver,"StartChatVCTableView", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotCallingPageObjects(AppiumDriver<MobileElement> myDriver){ driver= (IOSDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(driver), this); try { waitUntilDisplayed(driver,"CallVCView", true, 10); } catch (InterruptedException e) { e.printStackTrace(); } }
public RiotVerifyDevicePageObjects(AppiumDriver<MobileElement> myDriver) { driver=(IOSDriver<MobileElement>) myDriver; PageFactory.initElements(new AppiumFieldDecorator(myDriver), this); try { waitUntilDisplayed(driver,"//XCUIElementTypeWindow/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]", true, 5); } catch (InterruptedException e) { e.printStackTrace(); } }