Is it possible to use Selenium WebDriver for automating desktop applications?

天涯浪子 提交于 2019-12-10 15:53:53

问题


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.

So I'm curious about if is it possible to use Selenium WebDriver for automating desktop applications, which are created with web technologies (e.g. Electron)?

I have succesfully wrote some Selenium/Java tests for "Slack Web Application" (Slack is developed using Electron framefork)

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?

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);
}

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


回答1:


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




回答2:


If you're testing just electron apps, check out spectron which is designed for this purpose.

When I'm testing the development version of my app I run tests like:

const Application = require('spectron').Application

...

beforeEach(function () {
  this.app = new Application({
    path: './node_modules/electron/dist/electron.exe',
    args: ['./www/']
  });

  return this.app.start()
})

afterEach(function () {
  if (this.app && this.app.isRunning()) {
    return this.app.stop()
  }
})

it('shows an initial single window', function () {
  return this.app.client
    .getWindowCount()
    .should.eventually.equal(1)
})

To test a production app, just modify the path passed to the Application options.



来源:https://stackoverflow.com/questions/41656637/is-it-possible-to-use-selenium-webdriver-for-automating-desktop-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!