<tfoot id='QhFFx'></tfoot>
  • <i id='QhFFx'><tr id='QhFFx'><dt id='QhFFx'><q id='QhFFx'><span id='QhFFx'><b id='QhFFx'><form id='QhFFx'><ins id='QhFFx'></ins><ul id='QhFFx'></ul><sub id='QhFFx'></sub></form><legend id='QhFFx'></legend><bdo id='QhFFx'><pre id='QhFFx'><center id='QhFFx'></center></pre></bdo></b><th id='QhFFx'></th></span></q></dt></tr></i><div id='QhFFx'><tfoot id='QhFFx'></tfoot><dl id='QhFFx'><fieldset id='QhFFx'></fieldset></dl></div>

      <small id='QhFFx'></small><noframes id='QhFFx'>

        <legend id='QhFFx'><style id='QhFFx'><dir id='QhFFx'><q id='QhFFx'></q></dir></style></legend>
        • <bdo id='QhFFx'></bdo><ul id='QhFFx'></ul>
      1. Selenium2 和 webdriver 的一个很好的工作示例

        时间:2023-07-13
          <tbody id='CW1NX'></tbody>
          <bdo id='CW1NX'></bdo><ul id='CW1NX'></ul>
          <i id='CW1NX'><tr id='CW1NX'><dt id='CW1NX'><q id='CW1NX'><span id='CW1NX'><b id='CW1NX'><form id='CW1NX'><ins id='CW1NX'></ins><ul id='CW1NX'></ul><sub id='CW1NX'></sub></form><legend id='CW1NX'></legend><bdo id='CW1NX'><pre id='CW1NX'><center id='CW1NX'></center></pre></bdo></b><th id='CW1NX'></th></span></q></dt></tr></i><div id='CW1NX'><tfoot id='CW1NX'></tfoot><dl id='CW1NX'><fieldset id='CW1NX'></fieldset></dl></div>

            <small id='CW1NX'></small><noframes id='CW1NX'>

              <tfoot id='CW1NX'></tfoot>

              • <legend id='CW1NX'><style id='CW1NX'><dir id='CW1NX'><q id='CW1NX'></q></dir></style></legend>
                1. 本文介绍了Selenium2 和 webdriver 的一个很好的工作示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在使用 selenium 1,但现在想迁移到 selenium2/webdriver.老实说,我觉得从 selenium2/webdriver 开始有点困难.本质上,我不知道如何在页面对象之间工作.这是我的例子:

                  I've been using selenium 1, but now want to migrate to selenium2/webdriver. To be honest, I find a little bit difficult to start with selenium2/webdriver. In essence I don't know how to work between page objects. Here is my example:

                  public class LoginPage {
                      private final WebDriver driver;
                  
                      public LoginPage(WebDriver driver) {
                          this.driver = driver; 
                      }
                  
                      public void loginAs(String username, String password) {
                          driver.get("http://url_to_my_webapp");        
                          driver.findElement(By.id("username")).sendKeys(username);
                          driver.findElement(By.id("pwd")).sendKeys(password);
                          driver.findElement(By.className("button")).submit();                  
                      }
                  
                      public static void main(String[] args){
                          LoginPage login = new LoginPage(new FirefoxDriver());
                          login.loginAs("user", "pass");
                      }
                  }
                  

                  现在,用户登录后,会重定向到不同的页面.据我了解,我现在应该创建一个代表当前页面的新页面对象......事实是我不知道如何?我在哪里可以找到一些超越hello world"级别的优秀工作示例?我应该如何继续这个例子?

                  Now, after user is logged in, a redirection to different page occurs. As far as I understand, I should now make a new page object that represents current page... The fact is I don't know how? Where can I find some good working examples which are going beyond "hello world" level? How should I continue this example?

                  提前致谢!

                  推荐答案

                  这些网站都给出了一些例子:

                  These sites both give some examples:

                  http://luizfar.wordpress.com/2010/09/29/page-objects/

                  http://www.wakaleo.com/blog/selenium-2-web-driver-the-land-where-page-objects-are-king

                  这个页面给出了一些关于使用 PageFactory 来支持页面对象的细节:http://code.google.com/p/selenium/wiki/PageFactory

                  This page gives some details on using PageFactory to support page objects: http://code.google.com/p/selenium/wiki/PageFactory

                  您可以通过为每个页面创建一个类来扩展您的示例以使用页面对象,例如:

                  You could extend your example to work with page objects by creating a class for each page, e.g.:

                  public class MainPage 
                  { 
                    private final WebDriver driver;  
                  
                    public MainPage(WebDriver driver) 
                    {     
                      this.driver = driver;  
                    }   
                  
                    public void doSomething() 
                    {      
                      driver.findElement(By.id("something")).Click;     
                    }
                  } 
                  

                  并更改 loginAs 以返回一个表示浏览器在登录后导航到的页面的类:

                  and changing loginAs to return a class that represents the page that the browser navigates to after login:

                  public MainPage loginAs(String username, String password) 
                  {       
                      driver.get("http://url_to_my_webapp");             
                      driver.findElement(By.id("username")).sendKeys(username);     
                      driver.findElement(By.id("pwd")).sendKeys(password);     
                      driver.findElement(By.className("button")).submit();
                      // Add some error checking here for login failure
                      return new MainPage(driver);                   
                  }
                  

                  这篇关于Selenium2 和 webdriver 的一个很好的工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口 下一篇:如何使用 Selenium Webdriver 处理浏览器级别的通知

                  相关文章

                  • <bdo id='lnHk1'></bdo><ul id='lnHk1'></ul>
                  <tfoot id='lnHk1'></tfoot><legend id='lnHk1'><style id='lnHk1'><dir id='lnHk1'><q id='lnHk1'></q></dir></style></legend>

                      <i id='lnHk1'><tr id='lnHk1'><dt id='lnHk1'><q id='lnHk1'><span id='lnHk1'><b id='lnHk1'><form id='lnHk1'><ins id='lnHk1'></ins><ul id='lnHk1'></ul><sub id='lnHk1'></sub></form><legend id='lnHk1'></legend><bdo id='lnHk1'><pre id='lnHk1'><center id='lnHk1'></center></pre></bdo></b><th id='lnHk1'></th></span></q></dt></tr></i><div id='lnHk1'><tfoot id='lnHk1'></tfoot><dl id='lnHk1'><fieldset id='lnHk1'></fieldset></dl></div>

                      <small id='lnHk1'></small><noframes id='lnHk1'>