我正在尝试使用初始设置从 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/