java - 如何在使用 Serenity BDD 的同时为 Chrome 设置日志记录首选项?

标签 java selenium junit serenity-bdd

我正在尝试使用初始设置从 Chrome 中提取控制台日志,需要为 chrome webdriver 设置参数(来自 Capturing browser logs with Selenium ):

System.setProperty("webdriver.chrome.driver", "c:\\path\\to\\chromedriver.exe");        
DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

在让 Serenity BDD 使用来自 (net.thucydides.core.annotations.Managed) 的 @Managed 管理我的 WebDriver 的同时,我如何让它工作?

我正在使用(JUnit + Selenium + Serenity BDD),例如我当前的布局测试如下:
@RunWith(SerenityRunner.class) 
public class UserLoginSuccessfulIT {

@Managed(driver="chrome")                              
WebDriver driver;

@Steps                                                                       
LoginSuccessfulSteps user;

  @Test
  public void user_logs_in_successfully() throws IOException{
     //GIVEN
     user.opens_loginpage();
     //WHEN
     user.userTypesUserPass("user", "pass");
     user.logs_in();
     //THEN
     user.sees_welcomepage();
     user.check_for_dead_links_from_file();

  }

}

最佳答案

您可以在 Restful 中拥有自己的运行者,并使用您想要的功能实例化驱动程序。
通过这样做,您可以配置和重定向日志。

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        plugin = {"pretty"},
        features = "<feature file path>",
        glue = {"<steps path as comma separated values"}
)
public class MyRunner {

       }

关于java - 如何在使用 Serenity BDD 的同时为 Chrome 设置日志记录首选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35888104/

相关文章:

Java 不会读取 Node.js 服务器

java - 带有用户名和密码的 JsonObjectRequest

java - Maven -> Update Project... 究竟是什么?

java - JUnit Spring with xml No Annotation 加载bean失败

java - 使用 Mockito 在 JUnit 中使用 PowerMock 和 PowerRule 获取 javassist.NotFoundException

html - 用于 div 类复合文本的 Selenium Webdriver 定位器

selenium - 我们可以在 testng.xml 的方法级别传递参数或任何属性吗?

java - 用spring写单元测试

java - JUnit 在预期异常后继续断言

java - Streaming 的多项操作能否打破 Demeter 法则?