首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Java环境下用org.openqa.selenium测试电子应用(Intellij)

在Java环境下用org.openqa.selenium测试电子应用(Intellij)
EN

Stack Overflow用户
提问于 2016-02-19 14:08:58
回答 1查看 3.7K关注 0票数 4

有办法在Java环境中使用cucumberselenium-webdriver为电子应用程序创建自动化场景吗?

我在Node.js上找到了一些electron.atom.io解决方案,但我更喜欢electron.atom.io

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-19 16:17:06

您可以在ChromeDriver中使用电子浏览器。尝试使用类似的设置创建WebDriver:

代码语言:javascript
复制
// If chromediver executable is not in your project directory, 
//  point to it with this system variable
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); 

Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("binary", "path/to/electron/binary");
chromeOptions.put("args", Arrays.asList(" path-to-electron-app"));
//eg.: chromeOptions.put("binary", "D:\\electron-quick-start\\node_modules\\electron-prebuilt\\dist\\electron.exe");
//     chromeOptions.put("args", Arrays.asList(" D:\\electron-quick-start"));
//  for some reason the app arg needs to follow a space on my Windows machine
    
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", chromeOptions);
capabilities.setBrowserName("chrome");

WebDriver driver = new ChromeDriver(capabilities);

在这里,path-to-electron-app是存储应用程序源(main.js)的目录,电子二进制文件是从构建过程中下载的依赖项中提取的。

或者,如果您想使用预编译的应用程序--它本身成为电子二进制文件,则可以使用以下方法:

代码语言:javascript
复制
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); 
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("binary", "D:\\my-electron-app.exe");

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", chromeOptions);
capabilities.setBrowserName("chrome");

WebDriver driver = new ChromeDriver(capabilities);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35507295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档