2013-07-25 61 views
1

我有selenium.properties,其中我指定了测试配置(baseURL,浏览器等)。这被ant脚本用来启动webdriver junit测试用例。现在我有几个junit测试方法,我只想在Firefox上运行。我想知道是否有一种方法可以使用JUnit注释完成此操作?我可以创建自定义注释吗?运行Webdriver Junit浏览器特定测试用例

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? 

回答

0

你可以很容易地用JUnit和你自己的跑步者做到这一点。事实上,Selenium WebDriver测试中有一个类似的工作代码 - 它只是倒退。 Selenium想要跳过针对特定浏览器的测试,因此他们引入了自定义的@Ignore注释。

看看JUnit4TestBase,SeleniumTestRunner,最后是TestIgnorance

您可以使用他们的想法做出相反的事情,只用期望的驱动程序运行测试。不过,我认为你需要自己写,因为我不知道有什么好的解决方案。

+0

感谢您的指点,我会看看这些课程,并会尽快与我分享我的发现。 – aeinstein83

+0

我能够完成使用自定义注释解释在这里:http://stackoverflow.com/questions/13590557/junit4-skip-tests-according-to-custom-java-annotations – aeinstein83

相关问题