如何自动测试Chrome打包的应用? [英] How to automate testing of Chrome packaged apps?

查看:73
本文介绍了如何自动测试Chrome打包的应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于常规网站,有多种工具可以对应用程序执行自动化的UI测试,例如.但是,如何针对Chrome打包应用执行此操作?我的应用程序大量使用特定于Chrome应用程序的API,因此无法将其托管为用于测试的常规网页.

For regular web sites there are various tools to perform automated UI testing of applications, e.g. Selenium. However, how do I do this for Chrome Packaged Apps? My applications heavily uses Chrome App-specific APIs, so hosting it as a regular web page for testing won't work.

有什么最佳实践或工具吗?

Any best practices or tools for this?

推荐答案

如果可以获取应用程序窗口句柄,则Selenium Webdriver仍然可以使用.我在一堆失败的测试结束时调用 driver.getAllWindowHandles()时偶然发现了这一点.测试失败是因为它们没有引用应用程序窗口句柄,但意外地,最后一次调用返回了两个窗口句柄,而不是一个.

If you can get the app window handle, then Selenium Webdriver will still work. I discovered this by accident when I had a call to driver.getAllWindowHandles() at the end of a bunch of failed tests. The tests failed because they didn't have the reference to the app window handle, but -- unexpectedly -- the last call to returned two window handles instead of one.

在调用 driver.getAllWindowHandles()之后,似乎应用程序窗口句柄从未出现过,但是如果您继续调用此函数,最终其回调将收到包含两个浏览器的窗口句柄数组[0]和应用[1]窗口句柄.我已经通过递归实现了它,但是没有一个简单的while循环(某些Webdriver是异步的).

It may seem like the app window handle never appears after calling driver.getAllWindowHandles(), but if you keep calling this function, eventually its callback will receive an array of window handles containing both the browser [0] and app [1] window handles. I've gotten this to work via recursion but not with a simple while loop (something something webdriver being asynchronous).

例如,如果您挖掘了webdriver的javascript实现,请尝试从与此相关的错误报告.

For example, if you dig the javascript implementation of webdriver, try running the following test from this relevant bug report.

describe('A chrome app html page', function() {
  var appHandle = "";
  var recursionDepth= 0, maxDepth = 100; // edit as necessary.
  function getAppWindow(){
    browser.driver.getAllWindowHandles().then(function(handles){   
      if(handles.length == 1){
        recursionDepth += 1;
        if (recursionDepth == maxDepth) return false;
        getAppWindow();
      }
      if(handles.length == 2){
        browser.driver.switchTo().window(handles[1]);
        browser.driver.getWindowHandle().then(function(currentHandle){
          console.log("handles are" + handles);
          console.log("current handle is " + currentHandle);
          appHandle = currentHandle;
        });
      }
    });
  }
  getAppWindow();
  it('is on the second window handle', function(){
    expect(browser.driver.getWindowHandle()).toEqual(appHandle);
  }, 20000);
}); 

正如Antony指出的那样,您将需要在某处设置--load-and-launch-app =标志.我的量角器配置文件如下所示:

You will need the --load-and-launch-app= flag set somewhere, as Antony has helpfully pointed out. My protractor config file looks like this:

exports.config = {
  seleniumAddress: '<address of server>',
  capabilities: {
    'browserName': 'chrome',
    'chromeOptions':{
      'args': ['load-and-launch-app=<path to app code directory>']
    }
  },
  specs: ['<path to tests>']
}

这篇关于如何自动测试Chrome打包的应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆