Java 类org.openqa.selenium.support.PageFactory 实例源码

项目:kheera    文件:PageObject.java   
/**
 * 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
            }
        }
    }
}
项目:kheera    文件:TestExecutionController.java   
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);
}
项目:automationAbstractions    文件:ApplicationPageStructuralFactory.java   
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();
        }
    }
项目:webapp    文件:AudioEditTest.java   
@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");
    }
}
项目:webapp    文件:VideoEditTest.java   
@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);
        }
    }
项目:riot-automated-tests    文件:RiotSettingsPageObjects.java   
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();
    }
}
项目:marathonv5    文件:JTreeDynamicTreeTest.java   
@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);
}
项目:selenide-appium    文件:SelenideAppiumFieldDecorator.java   
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;
}
项目:dungeonstory-java    文件:AlignmentIT.java   
@Override
public void setUp() throws Exception {
    super.setUp();

    loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class);
    loginPO.login("admin", "admin");
}
项目:dungeonstory-java    文件:AbilityIT.java   
@Override
public void setUp() throws Exception {
    super.setUp();

    loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class);
    loginPO.login("admin", "admin");
}
项目:dungeonstory-java    文件:NewUserIT.java   
@Override
public void setUp() throws Exception {
    super.setUp();

    // Use the PageFactory to automatically initialize fields.
    loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class);
}
项目:dungeonstory-java    文件:NewCharacterIT.java   
@Override
public void setUp() throws Exception {
    super.setUp();

    messages = Messages.getInstance(Locale.getDefault());

    loginPO = PageFactory.initElements(getDriver(), LoginPageObject.class);
    loginPO.login("admin", "admin");
}
项目:SeleniumCucumber    文件:PageBase.java   
public PageBase(WebDriver driver) {
    if(driver == null)
        throw new IllegalArgumentException("Driver object is null");

    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), this);
    this.driver = driver;
}
项目:XPathBuilder    文件:HomePageTest.java   
@Parameters({ "path" })
@BeforeClass
public void testInit(String path) {

    // Load the page in the browser
    webDriver.get(websiteUrl + path);
    homepage = PageFactory.initElements(webDriver, HomePage.class);
}
项目:webapp    文件:ProjectListTest.java   
@Test
public void testListNotEmpty() {

    ProjectListPage projectListPage = PageFactory.initElements(driver, ProjectListPage.class);
    Boolean isEmpty = projectListPage.checkIfListItemIsEmpty();

    assertTrue(isEmpty);
}
项目:webapp    文件:ApplicationCreateTest.java   
@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));
}
项目:automata    文件:GoogleBaseView.java   
/**
 * Define global elements here
 */

public GoogleBaseView(WebDriver driver, GenericDataObject data){
    this.driver = driver;
    this.data   = data;
    PageFactory.initElements(driver, this);
}
项目:codenvy    文件:LoginAndCreateOnpremAccountPage.java   
@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);
}
项目:webapp    文件:AllophoneCreateTest.java   
@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));
}
项目:webapp    文件:ImageCreateTest.java   
@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));
}
项目:pivotal-cla    文件:AdminLinkClaPage.java   
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);
}
项目:webapp    文件:LetterCreateTest.java   
@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));
}
项目:webapp    文件:LetterEditTest.java   
@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);
    }
}
项目:webapp    文件:WordEditTest.java   
@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);
    }
}
项目:webapp    文件:WordCreateTest.java   
@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));
}
项目:webapp    文件:StoryBookEditTest.java   
@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);
}
项目:webapp    文件:ErrorPageTest.java   
@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());
}
项目:riot-automated-tests    文件:RiotUnknownDevicesPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotNewChatPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotCallingPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotVerifyDevicePageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotCameraPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotCaptchaPageObject.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotPeopleTabPageObjects.java   
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.");
}
项目:riot-automated-tests    文件:RiotLoginAndRegisterPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotIncomingCallPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotContactPickerPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotNewChatPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotCallingPageObjects.java   
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();
    }
}
项目:riot-automated-tests    文件:RiotVerifyDevicePageObjects.java   
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();
    }
}