2014-12-02 66 views
0

我试图在TestNG中使用组功能,并试图自动化应用程序。TestNG中的组未遵循连续顺序

我写了3个测试。

package 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("[email protected]"); 
     driver.findElement(By.id("Bugzilla_password_top")).clear(); 
     driver.findElement(By.id("Bugzilla_password_top")).sendKeys("[email protected]"); 
     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首先执行即错误报告()正在执行。

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

已尝试使用“dependsOnGroups”,但面临同样的问题。

+1

首先,Java中的方法是明确无序的。这意味着TestNG无法确定您的意图测试顺序。其次,测试应该是独立的*,即每个测试都应该独立运行,不管之前运行哪些测试。所以,虽然技术上不是你的问题的答案,但正确的答案是:重构你的测试,以便顺序无关紧要。 – Cephalopod 2014-12-02 09:15:55

回答

0

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