久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='hT5rK'><style id='hT5rK'><dir id='hT5rK'><q id='hT5rK'></q></dir></style></legend>

    <i id='hT5rK'><tr id='hT5rK'><dt id='hT5rK'><q id='hT5rK'><span id='hT5rK'><b id='hT5rK'><form id='hT5rK'><ins id='hT5rK'></ins><ul id='hT5rK'></ul><sub id='hT5rK'></sub></form><legend id='hT5rK'></legend><bdo id='hT5rK'><pre id='hT5rK'><center id='hT5rK'></center></pre></bdo></b><th id='hT5rK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hT5rK'><tfoot id='hT5rK'></tfoot><dl id='hT5rK'><fieldset id='hT5rK'></fieldset></dl></div>
  • <small id='hT5rK'></small><noframes id='hT5rK'>

      • <bdo id='hT5rK'></bdo><ul id='hT5rK'></ul>

      1. <tfoot id='hT5rK'></tfoot>

        Java 和 Selenium:頁面對象中的靜態方法

        Java and Selenium: Static methods in Page Objects(Java 和 Selenium:頁面對象中的靜態方法)

        1. <legend id='zIBL4'><style id='zIBL4'><dir id='zIBL4'><q id='zIBL4'></q></dir></style></legend>

            <tbody id='zIBL4'></tbody>
          <tfoot id='zIBL4'></tfoot>

          • <small id='zIBL4'></small><noframes id='zIBL4'>

              <bdo id='zIBL4'></bdo><ul id='zIBL4'></ul>
              <i id='zIBL4'><tr id='zIBL4'><dt id='zIBL4'><q id='zIBL4'><span id='zIBL4'><b id='zIBL4'><form id='zIBL4'><ins id='zIBL4'></ins><ul id='zIBL4'></ul><sub id='zIBL4'></sub></form><legend id='zIBL4'></legend><bdo id='zIBL4'><pre id='zIBL4'><center id='zIBL4'></center></pre></bdo></b><th id='zIBL4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zIBL4'><tfoot id='zIBL4'></tfoot><dl id='zIBL4'><fieldset id='zIBL4'></fieldset></dl></div>
                • 本文介紹了Java 和 Selenium:頁面對象中的靜態方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當我嘗試在頁面對象中使用靜態方法時,我遇到了 NullPointerExceptions 問題.如果我使用非靜態方法,它工作正常.

                  I'm having trouble with NullPointerExceptions when I try using static methods in a page object. If I do it with non-static methods, it works fine.

                  非靜態版本:

                  public class ComplaintPage {
                  
                      private ExtendedWebDriver driver;
                  
                      @FindBy(css = "[data-selector=date-received-complaint]")
                      public WebElement dateComplaintReceoved;
                  
                      public ComplaintPage() {
                          driver = Browser.extendedDriver();
                          PageFactory.initElements(driver, this);
                      }
                  
                      public void setComplaintDate() {
                          dateComplaintReceoved.sendKeys(LocalDate.now().toString());
                      }
                  }
                  
                  Calling code:
                  
                  ComplaintPage complaintPage = new ComplaintPage;
                  complaintPage.setComplaintDate();
                  

                  這很好用.日期字段已設置.

                  This works fine. The date field is set.

                  靜態版

                  public class ComplaintPage {
                  
                      private static ExtendedWebDriver driver;
                  
                      @FindBy(css = "[data-selector=date-received-complaint]")
                      public static WebElement dateComplaintReceoved;
                  
                      public ComplaintPage() {
                          driver = Browser.extendedDriver();
                          PageFactory.initElements(driver, this);
                      }
                  
                      public void static setComplaintDate() {
                  *       dateComplaintReceoved.sendKeys(LocalDate.now().toString());
                      }
                  }
                  
                  Calling code:
                  
                  ComplaintPage.setComplaintDate();
                  

                  這不起作用,并在標有*"的行(訪問 WebElement 的行)上導致 java.lang.NullPointerException.

                  This does not work, and results in a java.lang.NullPointerException on the line marked with "*" (the line accessing the WebElement).

                  我有點喜歡在測試中使用像這樣的靜態方法,因為我真的看不出它有什么問題,而且它使代碼更易于閱讀.我以前在 C#/VS 中做過,但由于某種原因,我在這里遺漏了一些重要的東西.

                  I kind of like using static methods like this in test, since I don't really see a problem with it, and it makes the code even more easy to read. And I've done it before, in C#/VS, but for some reason I'm missing something important here.

                  推薦答案

                  NullPointerException 因為 PageFactory 的工作方式而被拋出.你看,當你創建一個 ComplaintPage 類的實例時,你正在調用它的構造函數:

                  NullPointerException is thrown because of how PageFactory works. You see, when you create an instance of ComplaintPage class, you are invoking its constructor:

                  public ComplaintPage() {
                          driver = Browser.extendedDriver();
                          PageFactory.initElements(driver, this);
                      }
                  

                  構造函數調用PageFactory類的initElements方法.此方法使用 Java 反射 API 初始化所有 WebElementList> 字段.它基本上將默認的 null 值更改為接口的實現.它還提供了一種 WebElement 的惰性實例化,這意味著 - WebElement 僅在需要時才被發現(尋找?) - 當您調用它們的操作時.

                  The constructor calls initElements method of PageFactory class. This method initializes all of WebElement and List<WebElement> fields with Java Reflection API. It basically changes the default null values to implementations of the interface. It also provides sort of Lazy instantiation of the WebElement which means - WebElements are found (looked for?) only when needed - when you invoke operations on them.

                  當您創建靜態方法和靜態 WebElements 時 - 您沒有調用類的構造函數,這導致不調用 initElements 方法.

                  When you created static methods and static WebElements - you did not call the constructor of the class, which lead to NOT invoking the initElements method.

                  使用 @FindBy 注釋的所有元素均未初始化.這就是為什么將 PageFactory 與靜態方法一起使用并不是一個好主意.

                  All of the elements annotated with @FindBy were not initialized. That's why it's not a good idea to use PageFactory with static methods.

                  您可以在靜態方法中找到帶有經典 driver.findElement 的元素,而不是使用 PageFactory.

                  Instead of using PageFactory you can just find the element with classic driver.findElement inside the static method.

                      public void static setComplaintDate(WebDriver driver) {
                          driver.findElement(By.cssSelector("[data-selector=date-received-complaint]")).sendKeys(LocalDate.now().toString());
                      }
                  

                  這篇關于Java 和 Selenium:頁面對象中的靜態方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

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

                      <bdo id='Y66yk'></bdo><ul id='Y66yk'></ul>
                      <tfoot id='Y66yk'></tfoot>

                        1. <i id='Y66yk'><tr id='Y66yk'><dt id='Y66yk'><q id='Y66yk'><span id='Y66yk'><b id='Y66yk'><form id='Y66yk'><ins id='Y66yk'></ins><ul id='Y66yk'></ul><sub id='Y66yk'></sub></form><legend id='Y66yk'></legend><bdo id='Y66yk'><pre id='Y66yk'><center id='Y66yk'></center></pre></bdo></b><th id='Y66yk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Y66yk'><tfoot id='Y66yk'></tfoot><dl id='Y66yk'><fieldset id='Y66yk'></fieldset></dl></div>
                          <legend id='Y66yk'><style id='Y66yk'><dir id='Y66yk'><q id='Y66yk'></q></dir></style></legend>
                              <tbody id='Y66yk'></tbody>

                            主站蜘蛛池模板: 91精品国产91久久综合桃花 | 成人精品在线观看 | 夜夜草天天草 | 久久精品国产亚洲 | 欧美日韩国产一区二区三区 | 日韩中文字幕 | 久久精彩视频 | 欧美11一13sex性hd | 在线国产一区二区三区 | 日日碰狠狠躁久久躁婷婷 | 亚洲精品一区在线观看 | 国产精品免费一区二区三区四区 | 九色在线视频 | 日韩欧美中文字幕在线观看 | 狠狠涩 | 久久综合九色综合欧美狠狠 | 老司机67194精品线观看 | 午夜影院免费体验区 | 日本一区二区视频 | 欧美精品99 | 午夜在线视频 | 国产清纯白嫩初高生在线播放视频 | 嫩草视频在线免费观看 | 香蕉视频久久久 | 久久国产精品视频观看 | 国产欧美日韩精品一区 | 国产小视频在线 | 蜜桃视频一区二区三区 | 亚洲精品一区在线 | 欧美a视频| 中文字幕第十一页 | 欧美精品第一区 | 久久精品一区二 | 日日天天 | 日本久久精 | 日本不卡一区 | 亚洲一区二区三区免费在线观看 | 久久精品欧美一区二区三区不卡 | 亚洲精品欧美 | 色黄网站| 日韩毛片中文字幕 |