Java 类org.openqa.selenium.By.ById 实例源码

项目:qaf    文件:LocatorUtilTest.java   
@DataProvider(name = "locatorDP")
public static Iterator<Object[]> testData() {
    ArrayList<Object[]> data = new ArrayList<Object[]>();

    data.add(new Object[]{"id=eleId", ById.class});
    data.add(new Object[]{"name=eleName", ByName.class});
    data.add(new Object[]{"css=#eleId.className", ByCssSelector.class});
    data.add(new Object[]{"tagName=div", ByTagName.class});
    data.add(new Object[]{"link=Link Text", ByLinkText.class});
    data.add(new Object[]{"partialLink=Link Text", ByPartialLinkText.class});
    data.add(new Object[]{"['css=#qa','name=eleName']", ByAny.class});

    // self descriptive
    data.add(new Object[]{"{'locator' : 'id=eleId'; 'desc' : 'locate element by id'}",
            ById.class});
    data.add(new Object[]{
            "{'locator' : 'name=eleName'; 'desc' : 'locate element by name'}",
            ByName.class});
    data.add(new Object[]{
            "{'locator' : 'css=#eleId.className'; 'desc' : 'locate element by css'}",
            ByCssSelector.class});

    data.add(new Object[]{
            "{'locator' : ['css=#qa','name=eleName']; 'desc' : 'locate element by css'}",
            ByAny.class});

    data.add(new Object[]{"xpath=//*[text()='Albany-Rensselaer, NY (ALB)']",
            ByXPath.class});
    return data.iterator();
}
项目:cinnamon    文件:LocatorRegistryTest.java   
@Test
public void shouldRegisterWhenFlattenedLocatorFileIsLoaded() throws URISyntaxException {
    File locatorFile = new File(LocatorRegistryTest.class.getResource("/conf/flattened/locator.yml").toURI());
    LocatorRegistry locatorRegistry = new LocatorRegistry(new Properties(), locatorFile);

    assertTrue(locatorRegistry.getLocator("my-button") instanceof ByCssSelector);
    assertTrue(locatorRegistry.getLocator("my-input") instanceof ByXPath);
    assertTrue(locatorRegistry.getLocator("my-frame") instanceof ById);

    assertEquals(new ByCssSelector("#mypage .mybutton"), locatorRegistry.getLocator("my-button"));
    assertEquals(new ByXPath("//input[@class='myinput']"), locatorRegistry.getLocator("my-input"));
    assertEquals(new ById("myframe"), locatorRegistry.getLocator("my-frame"));
}
项目:cinnamon    文件:LocatorRegistryTest.java   
@Test
public void shouldRegisterDefaultProfileWhenLocatorPropertyIsNotSet() throws URISyntaxException {
    File locatorFile = new File(LocatorRegistryTest.class.getResource("/conf/hierarchical/locator.yml").toURI());
    LocatorRegistry locatorRegistry = new LocatorRegistry(new Properties(), locatorFile);

    assertTrue(locatorRegistry.getLocator("my-button") instanceof ByCssSelector);
    assertTrue(locatorRegistry.getLocator("my-input") instanceof ByXPath);
    assertTrue(locatorRegistry.getLocator("my-frame") instanceof ById);

    assertEquals(new ByCssSelector("#mypage .mybutton"), locatorRegistry.getLocator("my-button"));
    assertEquals(new ByXPath("//input[@class='myinput']"), locatorRegistry.getLocator("my-input"));
    assertEquals(new ById("myframe"), locatorRegistry.getLocator("my-frame"));
}
项目:cinnamon    文件:LocatorRegistryTest.java   
@Test
public void shouldRegisterUserSpecifiedProfileWhenLocatorPropertyIsSet() throws URISyntaxException {
    Properties properties = new Properties();
    properties.setProperty("locator", "override");
    File locatorFile = new File(LocatorRegistryTest.class.getResource("/conf/hierarchical/locator.yml").toURI());
    LocatorRegistry locatorRegistry = new LocatorRegistry(properties, locatorFile);

    assertTrue(locatorRegistry.getLocator("my-button") instanceof ByCssSelector);
    assertTrue(locatorRegistry.getLocator("my-input") instanceof ByXPath);
    assertTrue(locatorRegistry.getLocator("my-frame") instanceof ById);

    assertEquals(new ByCssSelector("#overridepage .overridebutton"), locatorRegistry.getLocator("my-button"));
    assertEquals(new ByXPath("//input[@class='myinput']"), locatorRegistry.getLocator("my-input"));
    assertEquals(new ById("myframe"), locatorRegistry.getLocator("my-frame"));
}