2015-10-19 87 views
-1

我一直在努力,我不得不關閉新標籤否則當前測試用例會因無法分配的XPath目錄失敗硒驅動程序。我注意到即時通訊調用了3次webdriver,任何人都可以引導我通過我犯的錯誤?好心提醒 。感謝您提前硒無法關閉新標籤

SignIn_Action:

public class SignIn_ActionBuilder { 
    static WebDriver wd = new FirefoxDriver(); 

    public static void Execute(WebDriver driver) throws Exception{ 

     wd.get(Constant.URL); 

     wd.manage().window().maximize(); 

     wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 

     Home_Page.Skip_Advertising(wd).click(); 

     Home_Page.lnk_MyAccount(wd).click(); 

     LogIn_Page.txtbx_UserName(wd).sendKeys(Constant.Username); 

     LogIn_Page.txtbx_Password(wd).sendKeys(Constant.Password); 

     wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 

     LogIn_Page.btn_LogIn(wd).click(); 

     wd.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); 




    } 
} 

產品選擇:

public class ProductSelectionConfirmation_Action { 
    static WebDriver wd = new FirefoxDriver(); 



    public static void ThreeDigit_Execute(WebDriver driver) throws Exception{ 

      // This is to get the Product name on the Confirmation page with using getText()/click method 
      // Once some text is stored in this variable can be used later in any other class 

      wd.manage().wait(120); 
      wd.close(); 

      ConfirmationPlaceBet_Page.pick_PickLotteryNum1(wd).click(); 
      ConfirmationPlaceBet_Page.pick_PickLotteryNum2(wd).click(); 
      ConfirmationPlaceBet_Page.pick_PickLotteryNum3(wd).click(); 

      ConfirmationPlaceBet_Page.btn_ConfirmNumberToBet(wd).click(); 

      for (int i = 0; i < 49; i++) { 
       ConfirmationPlaceBet_Page.btn_IncreaseBet(wd).click(); 
      } 

      ConfirmationPlaceBet_Page.btn_ProceedBet(wd).click(); 

      ConfirmationPlaceBet_Page.btn_ConfirmBet(wd).click(); 
      // This is all about Verification checks, these does not stop your execution but simply report fail at the end 
      // This is to check that if the value in the variable pick_PickLotteryNum1 is not null, then do this 

     } 
} 

測試用例:

public class Sobet_WBG_YiWanCai { 
    public WebDriver driver; 

    @Test(description = "WBG億萬彩 - 後三碼" , enabled = true) 
     public void f() throws Exception { 
      try{ 
       SignIn_ActionBuilder.Execute(driver); 
       ProductSelectionConfirmation_Action.ThreeDigit_Execute(driver); 
       Home_Page.lnk_LogOut(driver); 
       Home_Page.btn_LogOutDialog(driver); 
       driver.close(); 
      }catch (Exception e){ 

       Log.error(e.getMessage()); 
       throw (e); 
      } 

     } 
} 
+0

你的意思是'driver.close();'不工作?你得到什麼錯誤? –

+0

@HelpingHands即時通訊沒有得到任何錯誤,它不會關閉新標籤 –

+0

不需要調用網絡驅動器3 times..just把'公共靜態驅動程序的webdriver = NULL;'類「Sobet_WBG_YiWanCai」 –

回答

1

我可以看到一系列的與已發佈的代碼的問題。 在每個Action類中,您正在創建一個新的靜態Web驅動程序對象。

static WebDriver wd = new FirefoxDriver(); 

這意味着當類被調用時它會打開一個新的Firefox瀏覽器。 而且您還將webdriver對象傳遞給測試用例中的執行方法。但傳遞的webdriver永遠不會用在執行方法中。

public static void ThreeDigit_Execute(WebDriver driver) throws Exception{} 

您沒有使用該方法的任何行動driver對象,而是使用整個方法wd對象。

爲第一類更正後的代碼執行方法:

public class SignIn_ActionBuilder { 

    public static void Execute(WebDriver driver) throws Exception{ 

     driver.get(Constant.URL); 

     driver.manage().window().maximize(); 

     driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 

     Home_Page.Skip_Advertising(driver).click(); 

     Home_Page.lnk_MyAccount(driver).click(); 

     LogIn_Page.txtbx_UserName(driver).sendKeys(Constant.Username); 

     LogIn_Page.txtbx_Password(driver).sendKeys(Constant.Password); 

     driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 

     LogIn_Page.btn_LogIn(driver).click(); 

     driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); 
    } 
} 

而且從測試情況下,你必須創建一個webdriver的對象,並將其傳遞到執行方法。

public class Sobet_WBG_YiWanCai { 
public WebDriver driver; 

@Test(description = "WBG億萬彩 - 後三碼" , enabled = true) 
    public void f() throws Exception { 
     try{ 
      //Create the driver instance here. 
      driver = new FirefoxDriver(); 
      SignIn_ActionBuilder.Execute(driver); 
      ProductSelectionConfirmation_Action.ThreeDigit_Execute(driver); 
      Home_Page.lnk_LogOut(driver); 
      Home_Page.btn_LogOutDialog(driver); 
      driver.close(); 
     }catch (Exception e){ 

      Log.error(e.getMessage()); 
      throw (e); 
     } 

    } 
} 

而且您必須從所有操作類中刪除static WebDriver wd = new FirefoxDriver();行。

+0

事實上我刪除靜態webdriver的WD =新FirefoxDriver();但由於獲得了driver.get(Constant.URL)的空值而失敗; –