繁体   English   中英

如何在Selenium中使用带有注释的系统属性?

[英]Way to use system properties with annotation in Selenium?

有没有机会在Selenium中使用带有系统属性的注释?

@Test
public void
testSigninMobile()
{
   if(System.getProperty("browser").equals("iphone")){
        login();
   }else{
        driver.quit();
   } 

}

我想要这样的注释:

@Test if broswer is iphone, firefox but not if it is IE or Edge etc.
public void
testSigninMobile()
{...

我的意思是这样的情况:您有50个测试,但您的应用尚未为每个浏览器准备就绪。 我认为写50个这样的浏览器检查逻辑测试是愚蠢的吗?

您可以使用Capabilities-getBrowserName()在@Test方法内编写逻辑。

@Test
public void testSigninMobile()
{
   Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
   String browserName = cap.getBrowserName().toLowerCase();
   System.out.println(browserName);
   if("blabla".equalsIgnoreCase(browserName))
   {
      // Your code
   }
   else
   {
      throw new SkipException("Skipping this excecution");
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM