0

我正在尝试使用 selenium 和 testNG 在 eclipse 中执行一个 java 文件。我已将包名称从(默认包)更改为“内容”当我执行测试用例时,它抛出低于错误然后退出。

org.testng.TestNGException: 
Cannot instantiate class content.AddContent

这是课程

public class AddContent {
private WebDriver driver;
String parentWindow = driver.getWindowHandle().toString();
//private String baseUrl;
//private StringBuffer verificationErrors = new StringBuffer();

@BeforeMethod
public void setUp(ITestContext context) throws Exception {
//  String baseUrl = context.getCurrentXmlTest().getParameter("baseUrl");
driver = new FirefoxDriver();
 //baseUrl = "http://mavrick.fhru.com";
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

}


@DataProvider
public Object[][] getData(){
  Object[][] data = new Object[1][4];

  data[0][0] = "http://mavrick.fhru.com";
  data[0][1] = "superuser";
  data[0][2] = "Ring123";

return data;
 }

   @Test (dataProvider="getData")
 public void testAddContent(String baseUrl, String username, String password) throws    Exception {
System.out.println("Going to the URL "+baseUrl);
driver.get(baseUrl);
Thread.sleep(500);
System.out.println("Checking for title...");
String rtitle = driver.getTitle();
String etitle = "Digital Servers";
try{
Assert.assertEquals(rtitle, etitle);
}catch(Throwable t){
    System.out.println(" ERROR FOUND IN DS TITLE!! DS Login Page Title does not match");
    System.out.println("Found "+rtitle+". Expected "+etitle);
    System.out.println("The testcase will continue and will not be marked as failed.");
}
System.out.println("Maximizing the browser...");
driver.manage().window().maximize();
System.out.println("Entering "+username+" as Username...");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(username);
System.out.println("Entering "+password+" as Password...");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(password);
System.out.println("Clicking Sign in...");
driver.findElement(By.id("button")).click();
driver.findElement(By.id("contentImage")).click();
driver.findElement(By.id("bas")).click();
driver.switchTo().window("aapop");
driver.findElement(By.id("notselected")).click();
driver.findElement(By.id("url")).clear();
driver.findElement(By.id("url")).sendKeys("http://1.1.1.1/srsdsd/assests/ts1/gaming/");
driver.findElement(By.id("masks")).clear();
driver.findElement(By.id("masks")).sendKeys("*.mpeg");
//driver.findElement(By.className("ds_select_box")).click();
driver.findElement(By.xpath("//form[@id='subForm']/table/tbody/tr/td[2]/div/div/div")).click();
driver.findElement(By.xpath("//html/body/div/div[2]/div/div/div[2]/div/div/div[2]/form/table/tbody/tr/td[2]/div/div/ul/li[8]")).click();
//driver.findElement(By.tagName("Select")).click();
driver.findElement(By.xpath("//form[@id='subForm']/p[6]/div/div")).click();
driver.findElement(By.xpath("//html/body/div/div[2]/div/div/div[2]/div/div/div[2]/form/p[6]/div/ul/div/div/li[4]")).click();
//driver.findElement(By.xpath("//ul[@id='ul61']/li[8]")).click();
//driver.findElement(By.xpath("//ul[@id='ul87']/div/div/li[5]")).click();
//driver.findElement(By.id("ext-gen27")).click();
driver.findElement(By.xpath("//span[text() = 'Music']")).click();
driver.findElement(By.cssSelector("b")).click();
//driver.findElement(By.id("ext-gen46")).click();
driver.findElement(By.xpath("//tr/td[2]/em/button")).click();
driver.switchTo().window(parentWindow);
try {
    Thread.sleep(3000);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
driver.findElement(By.id("ext-gen205")).click();
System.out.println("Completed adding all the Channels. Now will Signout from DS");
driver.findElement(By.linkText("Sign Out")).click();
Thread.sleep(200);
System.out.println("Closing the browser and finishing the testcase.");
System.out.println("========================================================================");
}


@AfterMethod
 public void tearDown() throws Exception {
driver.quit();
//String verificationErrorString = verificationErrors.toString();
//if (!"".equals(verificationErrorString)) {
//  fail(verificationErrorString);
//}
}
}

请帮忙。是否有任何程序可以更改包名称?

4

3 回答 3

1

替换注释,

@BeforeMethod 与@BeforeClass@AfterMethod 与@AfterClass

然后执行你的测试

于 2013-10-30T18:19:48.380 回答
0

尝试项目->清理

然后执行 mvn eclipse:clean 和 mvn eclipse:eclipse。

于 2013-10-30T13:48:38.143 回答
0

如果电子表格格式有问题,有时我们会得到“无法实例化类”TestNG 异常。因此,如果您从电子表格中获取数据,请检查格式。

于 2016-02-17T10:30:38.780 回答