TestNG中的组不遵循连续顺序

时间:2014-12-02 09:04:24

标签: testng

我试图在TestNG中使用群组功能,并尝试自动化应用程序。

我写了3个测试。

包com.sonata.testng;

import org.openqa.selenium.By;
//import org.openqa.selenium.WebElement;
//import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;



public class Bugzilla_Groups extends Bugzilla_BaseClass{

   @BeforeSuite(groups = {"functional test"})
    public void initializeTest() throws Exception{
        super.setUp();
    }

    @Test(groups = {"functional test"})
    public void testLogin() throws Exception {
        driver.get(baseUrl);
        System.out.println("Login Test start");
        driver.findElement(By.id("login_link_top")).click();
        driver.findElement(By.id("Bugzilla_login_top")).clear();
        driver.findElement(By.id("Bugzilla_login_top")).sendKeys("jeevan.anekal@gmail.com");
        driver.findElement(By.id("Bugzilla_password_top")).clear();
        driver.findElement(By.id("Bugzilla_password_top")).sendKeys("testuser@123");
        driver.findElement(By.id("log_in_top")).click();


       System.out.println("Login Test Executed");
       Thread.sleep(5000);


    }

    @Test(groups = {"functional test"})
    public void BugReport() throws Exception {

        //driver.get(baseUrl);
        System.out.println("BugReport Test start");
        driver.findElement(By.id("enter_bug")).click();
            driver.findElement(By.linkText("Widgets")).click();
            new Select(driver.findElement(By.id("bug_severity"))).selectByVisibleText("trivial");
            new Select(driver.findElement(By.id("cf_drop_down"))).selectByVisibleText("---");
            new Select(driver.findElement(By.id("rep_platform"))).selectByVisibleText("Macintosh");
            new Select(driver.findElement(By.id("op_sys"))).selectByVisibleText("Mac OS X 10.0");
            driver.findElement(By.id("short_desc")).clear();
            driver.findElement(By.id("short_desc")).sendKeys("OS crashed");
            driver.findElement(By.id("comment")).clear();
            driver.findElement(By.id("comment")).sendKeys("Os debugging issue");
            driver.findElement(By.cssSelector("#attachment_false>input")).click();
            driver.findElement(By.id("data")).sendKeys("C:\\Users\\jeevan.s\\Downloads\\Locators_groups_1_0_2.pdf");

              System.out.println("BugReport Test Executed");
    }

    @Test(groups = {"functional test"})
    public void Reports() throws Exception {

        driver.get(baseUrl);
        System.out.println("Report Test start");
            //driver.findElement(By.cssSelector("#account > span")).click();
            driver.findElement(By.linkText("Reports")).click();
            driver.findElement(By.linkText("Duplicates")).click();
            driver.findElement(By.id("openonly")).click();
            driver.findElement(By.id("visiblelist")).click();

            System.out.println("Reports Test Executed");
    }

    @AfterSuite(groups = {"functional test"})
    public void testCleanup(){
        super.teardown();

    }   
}

当我尝试执行时,首先执行test2,即执行bugReport()。

由于我的test2要报告错误,所以应首先执行test1。

尝试使用" dependsOnGroups" ,但面临同样的问题。

1 个答案:

答案 0 :(得分:0)

您正在查看依赖于其他测试的测试。您需要在@Test注释中使用dependsOnMethods而不是dependsOngroups。