首页 文章

是否可以使用Selenium WebDriver自动化桌面应用程序?

提问于
浏览
4

我正准备编写目前处于开发初期的Web /桌面应用程序的自动化测试 . 将使用的技术是Laravel,VueJS和最重要的电子框架 . Electron是一个使用JavaScript,HTML和CSS等Web技术创建本机应用程序的框架 .

所以我很好奇 if is it possible to use Selenium WebDriver for automating desktop applications, which are created with web technologies (e.g. Electron)?

我成功地为“Slack Web Application”编写了一些Selenium / Java测试(Slack是使用Electron framefork开发的)

现在我想尝试使用相同的测试来测试“Slack Desktop App” . 如果有可能,也许我可以更改“SetupSelenium”@Before Method?

这是我最初用于基于Web的应用程序的“SetupSelenium”方法:@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

2 回答

  • 1

    创建 ChromeDriver 时需要设置一些 ChromeOptions ,如:

    ChromeOptions options = new ChromeOptions();
    options.setBinary(new File("C:\\path\\to\\slack.exe"));
    
    ChromeDriver driver = new ChromeDriver(options);
    

    关于这个主题的Electron文档中也有一个教程:https://xwartz.gitbooks.io/electron-gitbook/content/en//tutorial/using-selenium-and-webdriver.html

  • 0

    如果您只测试电子应用,请查看专为此目的而设计的spectron .

    当我测试我的应用程序的开发版本时,我运行以下测试:

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

    要测试 生产环境 应用程序,只需修改 path 传递给 Application 选项 .

相关问题