在同一个类文件中的第二个@test方法中使用数据提供程序未成功运行

时间:2018-05-17 13:40:21

标签: java selenium selenium-webdriver testng testng-dataprovider

根据我的要求,我在屏幕上有“添加”按钮,出现在“ClassC”中。它会打开弹出模块。我可以在其中添加更多数量的值并保存。

我的代码使用一个带有数据提供程序迭代的@Test方法运行。但是经过一次迭代后失败了。因此,我使用数据提供程序创建了一个额外的@test方法。

第一个@test方法成功运行后代码失败。找不到第一个元素来自第二个@test方法。

失败:列(“遇到”,“帐户”,“遭遇”)org.openqa.selenium.TimeoutException预期条件失败:等待By.xpath定位的元素的可见性:// * [@ id ='txtDisplayName '](尝试持续4秒,间隔500毫秒)。

public class classc extends classb {

@Test
public void Create()
{
// Redirection to the screen
    obj1.actiononMenu(driver, wait, "//abbr[@class='ti-settings']", "//samp[text() = 'Focus']", "//li[2]/ul/li[1]/a");

long focusauditTimetaken = (long) obj1.javatimeout(driver);
    this.wait = obj1.explicitWait(driver, (int) focusauditTimetaken);

    // Clicking add button
    WebElement addButton = obj1.selectElement(wait, "//div[2]/button");
    obj1.clickElement(addButton);

}

@Test(dataProvider = "addingColumns")
public void columns(String displayName, String columnName, String uniqueName)
{
    // Passing first value from the DataProvider (displayName)  
    WebElement displayColumn = obj1.selectElement(wait, "//*[@id='txtDisplayName']");
    obj1.clickElement(displayColumn);
    obj1.sendtext(displayColumn, displayName);

// Passing second value from the DataProvider (columnName)  
    WebElement columnDropdown = obj1.selectElement(wait, "//div[contains(text(), 'Select Column Name')]");
    obj1.clickElement(columnDropdown);

    obj1.dropdownfilter(driver, wait, "//div[@class='filter']/input", columnName);

// Passing thrid value from the Data Provider (uniqueName)
    WebElement uniqueDropdown = obj1.selectElement(wait, "//div[contains(text(), 'Select Column')]");
    obj1.clickElement(uniqueDropdown);

    obj1.dropdownfilter(driver, wait, "//div[@class='filter']/input", uniqueName);

// Save first set values 
    WebElement addcolumnButton = obj1.selectElement(wait, "//button[@class='button create hvr-glow hvr-icon']");
    obj1.clickElement(addcolumnButton);


}

@DataProvider(name = "addingColumns")
public Object[][] addColumns()
{
    return new Object[][]
            {
        {"AA","BB","CC"},
        {"11","22","33"}
            };
            }

}

c类扩展了B类。

public class ClassB extends ClassA{

@Test
public void project() {

    try {
        obj1.implicitWait(driver, 10);          
        WebElement groupName = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@class='placeholder']"))));
        groupName.click();

        WebElement inputText = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@class='filter']//input"))));
        inputText.click();
        inputText.sendKeys("Par");
        inputText.sendKeys(Keys.DOWN);
        inputText.sendKeys(Keys.ENTER);

        long timetaken = (long) obj1.javatimeout(driver);
        this.wait = obj1.explicitWait(driver, (int) timetaken); 

    } catch (Exception e) {
        System.out.println("Project group not selected " +e);
        // TODO: handle exception
    }

}

B类扩展了A类。

public class ClassA{

WebDriver driver;
WebDriverWait wait;

Commonclass obj1 = new Commonclass();

@BeforeSuite
public void callbrowser()
{
    this.driver = obj1.selectBrowser(driver, "Chrome");

}

@Test
public void login()
{
    driver.get("https://Link Goes here");

    long timetaken = (long) obj1.javatimeout(driver);
    wait = obj1.explicitWait(driver, (int) timetaken);

    WebElement signin = obj1.selectElement(wait, "//*[@id='txtSigninID']");
    obj1.sendtext(signin, "My Name");

    WebElement password = obj1.selectElement(wait, "//*[@id='txtPassword']");
    obj1.sendtext(password, "my password");

    WebElement submit = obj1.selectElement(wait, "//*[@name='btnSignIn']");
    obj1.clickElement(submit);
}

}

如果使用单个@test方法,则会运行整个代码。为什么单个类中的两个@test方法不起作用。我在下面添加了testng.xml。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="com.abc.def.aaa.classa"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

0 个答案:

没有答案