[英]Run Webdriver Junit browser specific test cases
I have selenium.properties in which i specify the test configuration (baseURL, browser etc). 我有selenium.properties,其中指定了测试配置(baseURL,浏览器等)。 This is used by ant script to kick off webdriver junit test cases.
ant脚本使用它来启动webdriver junit测试用例。 Now I have few junit test methods, that i want to run only on Firefox.
现在,我只有几个junit测试方法,只想在Firefox上运行。 I was wondering if there a way i can accomplish this using JUnit annotations?
我想知道是否有一种方法可以使用JUnit注释完成此任务? can i create custom annotations?
我可以创建自定义注释吗?
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?
You can easily do this with JUnit with your own runner. 您可以使用自己的运行程序使用JUnit轻松完成此操作。 In fact, there is a similar working code in Selenium WebDriver test - it's just backwards.
实际上,Selenium WebDriver测试中有一个类似的工作代码-只是倒退。 The Selenium guys wanted to skip some tests for particular browsers, so they introduced a custom
@Ignore
annotation. Selenium家伙想跳过针对特定浏览器的一些测试,因此他们引入了自定义
@Ignore
批注。
Take a look at JUnit4TestBase
, SeleniumTestRunner
and finally TestIgnorance
. 看一下
JUnit4TestBase
, SeleniumTestRunner
和最后的TestIgnorance
。
You can use their idea to make the opposite and only run the tests with the desired drivers. 您可以使用他们的想法相反,仅使用所需的驱动程序运行测试。 However, I think you'll need to write it yourself as I am not aware of any good solution out there.
但是,我认为您需要自己编写它,因为我不知道那里有什么好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.