angularjs - Protractor - 作为移动设备运行特定测试

标签 angularjs protractor angularjs-e2e e2e-testing

我有一个功能,它对移动网络/桌面有不同的作用。我的媒体查询在设备宽度上运行,例如:

@media only screen and (max-device-width: 1024px) { ... }

这意味着我不能只更改浏览器大小(它不会起作用):

browser.manage().window().setSize(320, 480);//不会被'device-size'媒体查询影响

我找到了更改设备功能的 chromeOptions 的选项。我尝试将其与 multiCapabilities 一起使用:

'use strict';

var config = require('infra-gruntfile/protractor-conf').config;

// old capabilities
// config.capabilities = {
//   browserName: 'chrome'
// };

config.multiCapabilities =
[
  {
    browserName: 'chrome',
    name: 'Unnamed Job',
    count: 1,
    shardTestFiles: false,
    maxInstances: 10,
    chromeOptions: {
      'mobileEmulation': {
        'deviceName': 'Apple iPhone 4'
      },
      args: [
        'incognito',
        'disable-extensions'
      ]
    },
    loggingPrefs: {
      browser: 'ALL'
    },
    specs: ['app/**/*.mobile.spec.js']
  },
  {
    browserName: 'chrome',
    specs: ['!app/**/*.mobile.spec.js']
  }
]

module.exports.config = config;

看起来 specs 不起作用(我正在尝试不同的 spec 选项)但所有这些选项都将在移动/非移动浏览器上运行所有测试。我需要测试移动测试才能在移动设备上运行,而所有其他测试都在常规浏览器上运行。

  1. 我是否有在测试期间以编程方式执行此操作(并且不使用配置)?

  2. 我当前的配置有什么问题吗?为什么 specs 对我不起作用?

最佳答案

看完this帖子我发现问题是特定于功能的规范是除了主要的config.specs。

这意味着我必须使用 specs: []

删除从我的基础设施配置文件到达的默认值
'use strict';

var config = require('infra-gruntfile/protractor-conf').config;

// old capabilities
// config.capabilities = {
//   browserName: 'chrome'
// };

config.specs = []; //This line solved my problem!

config.multiCapabilities =
[
  {
    browserName: 'chrome',
    name: 'Unnamed Job',
    count: 1,
    shardTestFiles: false,
    maxInstances: 10,
    chromeOptions: {
      'mobileEmulation': {
        'deviceName': 'Apple iPhone 4'
      },
      args: [
        'incognito',
        'disable-extensions'
      ]
    },
    loggingPrefs: {
      browser: 'ALL'
    },
    specs: ['app/**/*.mobile.spec.js']
  },
  {
    browserName: 'chrome',
    specs: ['!app/**/*.mobile.spec.js']
  }
]

module.exports.config = config;

关于angularjs - Protractor - 作为移动设备运行特定测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33757170/

相关文章:

javascript - 通过 JQuery 设置输入字段值会使 AngularJS 上所需的验证失败

javascript - 带有 constrainTo 的 jqPlot - 获取拖动点值

javascript - Protractor - getText() 返回数组而不是字符串

javascript - 无法在 Protractor 中使用 --suites 选项,出现 'Spec patterns did not match any files' 错误

selenium - Protractor 最大调用堆栈错误

javascript - 模拟 angularjs http 请求

javascript - 错误 : Timed out waiting for Protractor to synchronize with the page after 11001ms. “当用户 browser.getCurrentUrl()

asp.net - Application Insights 日志中的随机值 "Called asynchronously"

javascript - AngularJS 具有多个值的过滤器转发器

angularjs - Protractor - 由于有关 “RangeError: Maximum call stack size exceeded” 的错误,无法期待 Toast 通知