请教一下,在TestNG的一个方法(login)之后,打印语句不工作了。
package lectures;
import java.io.IOException;
public class DependencyAnnot extends TestBase {
// the code is written to check the inheritancce which helps us from hardcoding
// the values
public void OpenBrowser() throws IOException, InterruptedException {
System.out.println("executing the browser opening");
login();
}
}
登录方法是从 "TestBase "类中继承的,代码如下。
public class TestBase {
//System.setProperty("webdriver.chrome.driver","D:\\bharath\\Selenium\\chromedriver.exe");
public WebDriver driver = null;
@Test
public void login() throws IOException {
Properties prop = new Properties();
// properies class is used to scan and fileinput stream gives us location to scan
FileInputStream fis = new FileInputStream("D:\\raj\\src\\lectures\\datadriven.properties");
prop.load(fis);
System.out.println(prop.getProperty("username"));
System.out.println("opening browser");
// instead of hard-coding the browser we are using datadriver folder to help us
// choose the correct browser
if (prop.getProperty("browser").contains("chrome"))// if the datadriven.properties file has browser = chrome use
// it else its firefox
{
driver = new ChromeDriver();
// a webdriver defined in if statemetn is only valid in that if statemeent so
// its better to define after class
} else {
driver = new FirefoxDriver();
}
driver.get(prop.getProperty("url"));
System.out.println("closing browser");
}
我假设你的父版login()方法现在是一种你想在不同的测试中多次重用的工具。
所以这本身已经不是一个测试了。
将'OpenBrowser'方法上的@Test注解移到子类中。并从login()中删除它
测试框架只执行带有'@Test'注解的方法。