zoukankan      html  css  js  c++  java
  • begin

    PageObject模式:

    /**
     * Takes a username and password, fills out the fields, and clicks "login".
     * @return An instance of the AccountPage
     */
    public AccountPage loginAsUser(String username, String password) {
      WebElement loginField = driver.findElement(By.id("loginField"));
      loginField.clear();
      loginField.sendKeys(username);
    
      // Fill out the password field. The locator we're using is "By.id", and we should
      // have it defined elsewhere in the class.
      WebElement passwordField = driver.findElement(By.id("password"));
      passwordField.clear();
      passwordField.sendKeys(password);
    
      // Click the login button, which happens to have the id "submit".
      driver.findElement(By.id("submit")).click();
    
      // Create and return a new instance of the AccountPage (via the built-in Selenium
      // PageFactory).
      return PageFactory.newInstance(AccountPage.class);
    }

    样例:

    public class GoogleSearchPage extends LoadableComponent<GoogleSearchPage> {
      private final WebDriver driver;
      private GSPFluentInterface gspfi;
    
      public class GSPFluentInterface {
        private GoogleSearchPage gsp;
    
        public GSPFluentInterface(GoogleSearchPage googleSearchPage) {
            gsp = googleSearchPage;
        }
    
        public GSPFluentInterface clickSearchButton() {
            gsp.searchButton.click();
            return this;
        }
    
        public GSPFluentInterface setSearchString( String sstr ) {
            clearAndType( gsp.searchField, sstr );
            return this;
        }
      }
    
      @FindBy(id = "gbqfq") private WebElement searchField;
      @FindBy(id = "gbqfb") private WebElement searchButton;
      public GoogleSearchPage(WebDriver driver) {
        gspfi = new GSPFluentInterface( this );
        this.get(); // If load() fails, calls isLoaded() until page is finished loading
        PageFactory.initElements(driver, this); // Initialize WebElements on page
      }
    
      public GSPFluentInterface withFluent() {
        return gspfi;
      }
    
      public void clickSearchButton() {
        searchButton.click();
      }
    
      public void setSearchString( String sstr ) {
        clearAndType( searchField, sstr );
      }
    
      @Override
      protected void isLoaded() throws Error {
        Assert.assertTrue("Google search page is not yet loaded.", isSearchFieldVisible() );
      }
    
      @Override
      protected void load() {
        if ( isSFieldPresent ) {
          Wait<WebDriver> wait = new WebDriverWait( driver, 3 );
          wait.until( visibilityOfElementLocated( By.id("gbqfq") ) ).click();
        }
      }
    }
    

     Selenium官网:

    https://www.w3.org/TR/webdriver/#dependencies

    https://seleniumhq.github.io/docs/

    Selenium_doc

     https://seleniumhq.github.io/selenium/docs/api/java/index.html?overview-summary.html

  • 相关阅读:
    语文文法
    1223 递归下降语法分析程序设计
    有穷的自动机构造
    文法分析
    text
    0916 词法分析(3)
    "firstday"-软件工程
    实验四 递归下降语法分析程序设计
    构造该正规式的有穷状态自动机
    评论
  • 原文地址:https://www.cnblogs.com/wldan/p/10527046.html
Copyright © 2011-2022 走看看