这个问题显然是另一个问题的重复,但不是(标题使它看起来像是重复的) 首先,我在文件Demo.java中添加了一个eclipse中的testMethod:
package com.star.Simulation;
import org.testng.annotations.Test;//there are many
import org.testng.annotations.Test;//imports of the same
import org.testng.annotations.Test;//library because it's
import org.testng.annotations.Test;//done automatically
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.opera.OperaOptions;
public class Demo {
@Test
public void testMethod() throws InterruptedException {
System.setProperty("webdriver.opera.driver", "/path/to/operadriver");
OperaOptions options = new OperaOptions();
options.addArguments("--no-sandbox");
options.addArguments("start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new OperaDriver(options);
driver.get("http://validaddress:validport/simulation/index.star");
driver.manage().window().maximize();
driver.findElement(By.id("formConnexion:login")).sendKeys("0100");
driver.findElement(By.id("formConnexion:password")).sendKeys("star");
driver.findElement(By.id("formConnexion:j_idt13")).click();
Thread.sleep(10000);
String aurl = driver.getCurrentUrl();
String eurl = "http://validaddress:validport/simulation/index.star";
if (aurl.equalsIgnoreCase(eurl))
System.out.println("failed");
else
System.out.println("success");
driver.quit();
}
}
接下来我已经生成了一个testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="1" allow-return-values="true">
<test thread-count="5" name="Test">
<classes>
<class name="com.star.Simulation.Demo"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
接下来,我已经在eclipse上对.java和.xml进行了多次测试,并获得了理想的结果,但是当我尝试使用以下命令在终端上测试.xml时:java -cp "./lib/*:./bin" org.testng.TestNG testng.xml
我得到了以下结果:
===============================================
Suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================
就像您一定已经看到我正在运行CentOS7机器一样,我尝试使用java8和java11,结果相同
(我的预期结果显然是Total tests run: 1
)
你能帮助我吗?预先感谢