是否可以使用Selenium WebDriver自动执行桌面应用程序? [英] Is it possible to use Selenium WebDriver for automating desktop applications?
问题描述
我正准备为当前处于开发初期的Web/桌面应用程序编写自动化测试.将使用的技术是Laravel,VueJS和最重要的Electron Framework. Electron是使用JavaScript,HTML和CSS等网络技术创建本机应用程序的框架.
I'm preparing to write automated tests for Web/Desktop application that is currently in the initial stage of development. The technologies that will be used are Laravel, VueJS and most important Electron Framework. Electron is a framework for creating native applications with web technologies like JavaScript, HTML, and CSS.
所以我很好奇是否可以使用Selenium WebDriver自动化由Web技术(例如Electron)创建的桌面应用程序?
我已经成功地为"Slack Web应用程序"编写了一些Selenium/Java测试(Slack是使用Electron framefork开发的)
I have succesfully wrote some Selenium/Java tests for "Slack Web Application" (Slack is developed using Electron framefork)
现在,我想尝试使用相同的测试来测试"Slack Desktop App".如果可能的话,也许我可以更改"SetupSelenium" @Before方法?
Now I want to try to use the same tests for testing "Slack Desktop App". If it is possible, maybe I can change "SetupSelenium" @Before Method?
这是我最初的基于Web的应用程序的"SetupSelenium"方法: @BeforeMethod
This is my initial "SetupSelenium" method for Web based application: @BeforeMethod
public void setupSelenium() {
baseUrl = "https://slack.com/";
System.setProperty("webdriver.chrome.driver", "C:\\UOOP\\WorkspaceJava\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to(baseUrl);
homePage = new HomePage(driver);
signInPage = new SignInPage(driver);
signInToYourTeamPage = new SignInToYourTeamPage(driver);
}
如果有人有任何帮助,我将感谢您的帮助...也许可以将二进制路径设置为slack.exe?
到: C:\ Users \ Danant \ AppData \ Local \ slack \ slack.exe
I appreciate help if anyone has any idea... Maybe to set binary path to slack.exe ??
To: C:\Users\Danant\AppData\Local\slack\slack.exe
推荐答案
创建ChromeDriver
时需要设置一些ChromeOptions
,例如:
You need to set some ChromeOptions
when creating the ChromeDriver
, like:
ChromeOptions options = new ChromeOptions();
options.setBinary(new File("C:\\path\\to\\slack.exe"));
ChromeDriver driver = new ChromeDriver(options);
There's a tutorial in the Electron documentation on this topic too: https://xwartz.gitbooks.io/electron-gitbook/content/en//tutorial/using-selenium-and-webdriver.html
这篇关于是否可以使用Selenium WebDriver自动执行桌面应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!