org.openqa.selenium.support.FindBy类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.openqa.selenium.support.FindBy类的一些代码示例,展示了FindBy类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FindBy类的具体详情如下:
包路径:org.openqa.selenium.support.FindBy
类名称:FindBy

FindBy介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-security

public static class HomePage {
  private WebDriver driver;
  @FindBy(tagName = "body")
  WebElement body;
  public HomePage(WebDriver driver) {
    this.driver = driver;
  }
  public void assertAt() {
    assertThat(this.body.getText()).isEqualToIgnoringWhitespace("ok");
  }
  static <T> T to(WebDriver driver, Class<T> page) {
    driver.get("http://localhost/");
    return PageFactory.initElements(driver, page);
  }
}

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class TestXHR2 {
  @ArquillianResource
  private URL contextRoot;
  private WebDriver browser;
  @FindBy
  private WebElement xhr1Trigger;
  @FindBy
  private WebElement xhr2Trigger;
  @FindBy
  private WebElement response1;
  @FindBy
  private WebElement response2;

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class TestInitializeNestedPageFragments {
  @FindBy(id = "foo")
  private InnerPageFragment innerPageFragment;
  @FindBy(id = "foo")
  private NestedStaticPageFragment nestedStaticPageFragment;

代码示例来源:origin: cukespace/cukespace

public class CukeBellyGlue {
  @ArquillianResource
  private URL deploymentUrl;
  private WebDriver browser;
  @FindBy(id = "bellyForm:mouth")
  private WebElement bellyMouth;
  @FindBy(id = "bellyForm:eatCukes")
  private WebElement bellyEat;

代码示例来源:origin: org.seleniumhq.webdriver/webdriver-support

private void assertValidFindBy(FindBy findBy) {
  if (findBy.how() != null) {
   if (findBy.using() == null) {
    throw new IllegalArgumentException("If you set the 'how' property, you must also set 'using'");
   }
  }

  Set<String> finders = new HashSet<String>();
  if (!"".equals(findBy.using())) finders.add("how: " + findBy.using());
  if (!"".equals(findBy.className())) finders.add("class name:" + findBy.className());
  if (!"".equals(findBy.id())) finders.add("id: " + findBy.id());
  if (!"".equals(findBy.linkText())) finders.add("link text: " + findBy.linkText());
  if (!"".equals(findBy.name())) finders.add("name: " + findBy.name());
  if (!"".equals(findBy.partialLinkText())) finders.add("partial link text: " + findBy.partialLinkText());
  if (!"".equals(findBy.tagName())) finders.add("tag name: " + findBy.tagName());
  if (!"".equals(findBy.xpath())) finders.add("xpath: " + findBy.xpath());

  // A zero count is okay: it means to look by name or id.
  if (finders.size() > 1) {
   throw new IllegalArgumentException(
           String.format("You must specify at most one location strategy. Number found: %d (%s)",
                   finders.size(), finders.toString()));
  }
 }
}

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class RequestGuardTestCase {
  @ArquillianResource
  private URL contextRoot;
  private WebDriver browser;
  @FindBy(id = "xhr")
  private WebElement xhr;
  @FindBy(id = "http")
  private WebElement http;
  @FindBy(id = "status")
  private WebElement status;

代码示例来源:origin: arquillian/arquillian-graphene

/**
 * An abstract class representing a simple test class using WebDriver and form.html as a web page. This class is intended to
 * be used for running in customized environment directly from a Java code: {@code JUnitCore.runClasses(AbstractTestClass.class);}
 *
 * @author <a href="mailto:mjobanek@redhat.com">Matous Jobanek</a>
 */
@RunWith(Arquillian.class)
@RunAsClient
public abstract class AbstractTestClass {

  @Drone
  private WebDriver browser;

  @FindBy(id = "root")
  private WebElement rootElement;

  @Test
  public abstract void testMethod();

  public void loadPage() {
    browser.get(Constants.SAMPLE_HTML_PATH);
    Graphene.waitAjax().until().element(rootElement).is().present();
  }

  protected WebDriver getBrowser() {
    return browser;
  }
}

代码示例来源:origin: arquillian/arquillian-graphene

public static class SimplePage {
  @FindBy(tagName="h1")
  private WebElement header;
  private Document document;
  @ArquillianResource
  private JavascriptExecutor javascriptExecutor;
  @ArquillianResource
  private GrapheneContext context;

代码示例来源:origin: org.seleniumhq.webdriver/webdriver-support

protected By buildByFromShortFindBy(FindBy findBy) {
 if (!"".equals(findBy.className()))
  return By.className(findBy.className());
 if (!"".equals(findBy.id()))
  return By.id(findBy.id());
 if (!"".equals(findBy.linkText()))
  return By.linkText(findBy.linkText());
 if (!"".equals(findBy.name()))
  return By.name(findBy.name());
 if (!"".equals(findBy.partialLinkText()))
  return By.partialLinkText(findBy.partialLinkText());
 if (!"".equals(findBy.tagName()))
  return By.tagName(findBy.tagName());
 if (!"".equals(findBy.xpath()))
  return By.xpath(findBy.xpath());
 // Fall through
 return null;
}

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class TestInitializeFindBys {
  private WebDriver browser;
  @ArquillianResource
  private URL contextRoot;
  @FindBys({ @FindBy(css = "#root"), @FindBy(tagName = "div"), @FindBy(tagName = "span") })
  private WebElement element;
  @FindBys({ @FindBy(css = "#root"), @FindBy(css = ".list") })
  private List<WebElement> elements;

代码示例来源:origin: spring-projects/spring-security

public static class DefaultLogoutPage {
  private WebDriver driver;
  @FindBy(css = "button[type=submit]")
  private WebElement submit;
  public DefaultLogoutPage(WebDriver webDriver) {
    this.driver = webDriver;
  }
  public DefaultLogoutPage assertAt() {
    assertThat(this.driver.getTitle()).isEqualTo("Confirm Log Out?");
    return this;
  }
  public DefaultLoginPage logout() {
    this.submit.click();
    return DefaultLoginPage.create(this.driver);
  }
  static DefaultLogoutPage to(WebDriver driver) {
    driver.get("http://localhost/logout");
    return PageFactory.initElements(driver, DefaultLogoutPage.class);
  }
}
public static class HomePage {

代码示例来源:origin: arquillian/arquillian-graphene

private WebDriver browser;
@FindBy(tagName="h1")
private WebElement header;
@ArquillianResource
private JavascriptExecutor javascriptExecutor;
@ArquillianResource
private GrapheneContext context;

代码示例来源:origin: com.epam.jdi/jdi-uitest-web

public static By findByToBy(FindBy locator) {
  if (locator == null) return null;
  if (!locator.id().isEmpty())
    return By.id(locator.id());
  if (!locator.className().isEmpty())
    return By.className(locator.className());
  if (!locator.xpath().isEmpty())
    return By.xpath(locator.xpath());
  if (!locator.css().isEmpty())
    return By.cssSelector(locator.css());
  if (!locator.linkText().isEmpty())
    return By.linkText(locator.linkText());
  if (!locator.name().isEmpty())
    return By.name(locator.name());
  if (!locator.partialLinkText().isEmpty())
    return By.partialLinkText(locator.partialLinkText());
  if (!locator.tagName().isEmpty())
    return By.tagName(locator.tagName());
  return null;
}

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class TestSwitchToFrame {
  @ArquillianResource
  private URL contextRoot;
  private WebDriver browser;
  @FindBy(css="h1")
  private WebElement h1;
  @FindBy(tagName="iframe")
  private WebElement iframe;

代码示例来源:origin: spring-projects/spring-security

public static class LoginForm {
  private WebDriver driver;
  private WebElement username;
  private WebElement password;
  @FindBy(css = "button[type=submit]")
  private WebElement submit;
  public LoginForm(WebDriver driver) {
    this.driver = driver;
  }
  public LoginForm username(String username) {
    this.username.sendKeys(username);
    return this;
  }
  public LoginForm password(String password) {
    this.password.sendKeys(password);
    return this;
  }
  public <T> T submit(Class<T> page) {
    this.submit.click();
    return PageFactory.initElements(this.driver, page);
  }
}

代码示例来源:origin: epam/JDI

public static By findByToBy(FindBy locator) {
  if (locator == null) return null;
  if (!"".equals(locator.id()))
    return By.id(locator.id());
  if (!"".equals(locator.className()))
    return By.className(locator.className());
  if (!"".equals(locator.xpath()))
    return By.xpath(locator.xpath());
  if (!"".equals(locator.css()))
    return By.cssSelector(locator.css());
  if (!"".equals(locator.linkText()))
    return By.linkText(locator.linkText());
  if (!"".equals(locator.name()))
    return By.name(locator.name());
  if (!"".equals(locator.partialLinkText()))
    return By.partialLinkText(locator.partialLinkText());
  if (!"".equals(locator.tagName()))
    return By.tagName(locator.tagName());
  return null;
}

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class TestWebElementWrapper {
  private WebDriver browser;
  @FindBy(css="#root span")
  private Wrapper1 wrapper1;
  @FindBy(css="#root span")
  private Wrapper2 wrapper2;
  @FindBy(tagName="select")
  private Select select;
  @ArquillianResource
  private URL contextRoot;

代码示例来源:origin: spring-projects/spring-security

public static class LoginForm {
    private WebDriver driver;
    private WebElement username;
    private WebElement password;
    @FindBy(css = "button[type=submit]")
    private WebElement submit;
    public LoginForm(WebDriver driver) {
      this.driver = driver;
    }
    public LoginForm username(String username) {
      this.username.sendKeys(username);
      return this;
    }
    public LoginForm password(String password) {
      this.password.sendKeys(password);
      return this;
    }
    public <T> T submit(Class<T> page) {
      this.submit.click();
      return PageFactory.initElements(this.driver, page);
    }
  }
}

代码示例来源:origin: epam/JDI

public static By findByToBy(FindBy locator) {
  if (locator == null) return null;
  if (!locator.id().isEmpty())
    return By.id(locator.id());
  if (!locator.className().isEmpty())
    return By.className(locator.className());
  if (!locator.xpath().isEmpty())
    return By.xpath(locator.xpath());
  if (!locator.css().isEmpty())
    return By.cssSelector(locator.css());
  if (!locator.linkText().isEmpty())
    return By.linkText(locator.linkText());
  if (!locator.name().isEmpty())
    return By.name(locator.name());
  if (!locator.partialLinkText().isEmpty())
    return By.partialLinkText(locator.partialLinkText());
  if (!locator.tagName().isEmpty())
    return By.tagName(locator.tagName());
  return null;
}

代码示例来源:origin: arquillian/arquillian-graphene

@RunWith(Arquillian.class)
@RunAsClient
public class TestSamplePageFragment {
  private WebDriver browser;
  @FindBy(id="root")
  private SamplePageFragment pageFragment;
  @FindBy(id="root")
  private SamplePageFragmentWithRootAsTheLastField pageFragmentWithRootAsTheLastField;
  @FindBy(id="span")
  private WebElement spanNotCorrect;
  @ArquillianResource
  private URL contextRoot;

相关文章