testng中方法为什么执行两次?

上一篇 / 下一篇  2012-07-03 00:41:24 / 个人分类:TestNG/Ant/Eclipse/Java

newtest.java

package COM.CITSAMER;
import org.testng.annotations.Test;
public class NewTest extends CommonClass {

@Test
public void bingSearchWithOpenNew() {
 getSignIn(username,password); 
    }   
}

CommonClass.java

package COM.CITSAMER;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class CommonClass {
 
 WebDriver driver = new FirefoxDriver(); 
 String baseUrl ="http://wwww.126.com";
 String username="dian***";
 String password="2198****";
 
@DataProvider(name = "test") 
public Object[][]createData() {
 
return new Object[][] { 
    { username, password},  
  }; 
 } 

@Test(dataProvider = "test")
public void getSignIn(String aUsername,String aPassword){
 driver.get(baseUrl);
 driver.findElement(By.id("idInput")).clear();
 driver.findElement(By.id("idInput")).sendKeys(aUsername);
 driver.findElement(By.id("pwdInput")).clear();
 driver.findElement(By.id("pwdInput")).sendKeys(aPassword);
 driver.findElement(By.id("loginBtn")).click();
 try {
  Thread.sleep(2000);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
if(!driver.getCurrentUrl().startsWith("http://webmail.mail.126.com/js4/main.jsp")){
 System.out.println("sign in not success, pls check..."); 
}
}
}


TAG:

MillionRoses 引用 删除 dian106106   /   2012-07-04 00:41:56
其实就是3个class的问题:
a类:CommonFuncitons.java
b类: 1.class TestsHelper extends CommonFunctions 2.存放所有的方法,即testcase
c类: Test.java 调用b类中的方法
public  class CommonFunctions { }
public partial class SVTTestsHelper : CommonFunctions {
commonFunction = new CommonFunctions();}
public class SVTTests{
            commonFunctions = new CommonFunctions();
            helper = new SVTTestsHelper();}
MillionRoses 引用 删除 dian106106   /   2012-07-03 23:38:54
CommonClass commonFunction = new CommonClass();
        commonFunction.getSignIn(username,password);
MillionRoses 引用 删除 dian106106   /   2012-07-03 00:46:39
输出结果:
PASSED: getSignIn("dian****", "2198***")
PASSED: bingSearchWithOpenNew
 

评分:0

我来说两句

日历

« 2024-05-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 74624
  • 日志数: 80
  • 建立时间: 2012-04-12
  • 更新时间: 2013-05-21

RSS订阅

Open Toolbar