Java 运行特定于Webdriver Junit浏览器的测试用例
我在selenium.properties中指定了测试配置(baseURL、浏览器等)。ant脚本使用它来启动webdriver junit测试用例。现在我有一些junit测试方法,我只想在Firefox上运行。我想知道是否有一种方法可以使用JUnit注释实现这一点?我可以创建自定义批注吗Java 运行特定于Webdriver Junit浏览器的测试用例,java,webdriver,junit4,Java,Webdriver,Junit4,我在selenium.properties中指定了测试配置(baseURL、浏览器等)。ant脚本使用它来启动webdriver junit测试用例。现在我有一些junit测试方法,我只想在Firefox上运行。我想知道是否有一种方法可以使用JUnit注释实现这一点?我可以创建自定义批注吗 my setup public class TestBase{ public static String baseURL = null; public static String brows
my setup
public class TestBase{
public static String baseURL = null;
public static String browser = null;
@BeforeClass
public static void webdriverSetUp() {
try {
FileInputStream fn = new FileInputStream(SELENIUM_PROP_FILE);
Properties selenium_properties = new Properties();
selenium_properties.load(fn);
baseURL = selenium_properties.getProperty("baseUrl");
browser = selenium_properties.getProperty("browser");
} catch (Exception e) {
e.printStackTrace();
}
if(browserg.equalsIgnoreCase("firefox")){
File profileDirectory = new File("./profile");
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
driver = new FirefoxDriver(profile);
}
}
//Test Class
public class TestCase1 extends TestBase{
@Test //run this case only if browser = firefox
public void test1(){
}
@Test //do not run this case if browser = chrome
public void test2(){
}
}
any pointers?
你可以用JUnit和你自己的跑步者轻松做到这一点。事实上,SeleniumWebDriver测试中有一个类似的工作代码——它只是向后的。Selenium想要跳过特定浏览器的一些测试,所以他们引入了一个自定义注释 看看,最后
您可以使用他们的想法来做相反的事情,并且只使用所需的驱动程序运行测试。但是,我认为您需要自己编写,因为我不知道有什么好的解决方案。感谢您的指点,我将查看这些类,并在我的工作正常后立即与大家分享我的发现。我可以使用此处介绍的自定义注释来完成: