gpt4 book ai didi

java - 无法使用 TestNG 在 Selenium Eclipse 中实例化类

转载 作者:行者123 更新时间:2023-12-01 13:54:42 25 4
gpt4 key购买 nike

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

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

这是类(class)

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);
//}
}
}

请帮忙。更改包名称是否需要遵循任何程序?

最佳答案

替换注释,

@BeforeMethod 与 @BeforeClass 和 @AfterMethod 与 @AfterClass

然后执行你的测试

关于java - 无法使用 TestNG 在 Selenium Eclipse 中实例化类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19679154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com