2015-10-19 92 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)的空值而失败; –