2016-06-14 75 views
0

为什么Selenium WebDriver命令不会显示在我的@Test(priority=2)上?每次我在@Test(priority=1)测试进入硒网络驱动器命令它只是不使用其他测试 -Selenium Web Driver和TESTNG

public class TestingTestNG { 
@Test(priority=1) 
public void TestingTestNG() throws InterruptedException{ 

    // Import FireFox Driver 
    WebDriver driver = new FirefoxDriver(); 


    // Open up Sand Page 
    driver.get("****"); 

    // Enter Usename and Password 

    // User 
    driver.findElement(By.id("userId")).sendKeys("****"); 
    Thread.sleep(3000); 

    // Password 
    driver.findElement(By.id("password")).sendKeys("****"); 
    Thread.sleep(3000); 

    // Click Login Button 
    driver.findElement(By.id("loginButton")).click(); 
} 

@Test(priority=2) 
public void test2(){ 
    driver. 

驱动程序的下拉列表。不显示,只显示它是一个类...任何建议?您driver结果在的

+0

[硒的webdriver和TestNG](http://stackoverflow.com/questions/37838987/selenium-webdriver-and-testng)的可能的复制 – Andrejs

回答

1

不正确的范围,请尝试更改范围如下:

public class TestingTestNG { 

// Import FireFox Driver 
WebDriver driver = new FirefoxDriver(); 

@Test(priority=1) 
public void TestingTestNG() throws InterruptedException{ 

    // Open up Sand Page 
    driver.get("****"); 


    .... 
} 

@Test(priority=2) 
public void test2(){ 
    driver. //and now you shall get what you are expecting 
} 

编辑 -

driver.findElement(By.xpath("//element x-path")).click() 

应在相同的语法

+1

无法用言语形容的感激之情,我,非常感谢! @nullpointer – user6401108

+0

欢迎。我们是否有这个选定的答案,然后完成线程? – nullpointer

+0

是的没有更多的问题!再次感谢你@nullpointer – user6401108

2

您需要申报工作你的驱动程序在@Test之外。

public class TestingTestNG { 

WebDriver driver = new FirefoxDriver(); 

@Test(priority=1) 
public void TestingTestNG() throws InterruptedException{ 
    // Open up Sand Page 
    driver.get("****"); 

    // Enter Usename and Password 

    // User 
    driver.findElement(By.id("userId")).sendKeys("****"); 
    Thread.sleep(3000); 

    // Password 
    driver.findElement(By.id("password")).sendKeys("****"); 
    Thread.sleep(3000); 

    // Click Login Button 
    driver.findElement(By.id("loginButton")).click(); 
} 

@Test(priority=2) 
public void test2(){ 
    driver. // here you will get your options.