如果套件中有多个文件,则Protractor --suite选项将失败

时间:2015-08-08 03:48:17

标签: jasmine protractor

第一次询问关于SO的问题,我希望我做得对。

每当我在一个包含多个文件的套件上运行protractor authenticated.conf.js --suite suitename时,它就会失败 - 它会因我protractor.helper.loginToPage();登录到基页(localhost:3000)而登录,然后抛出没有关闭网页的错误。

我通过在同一文件夹中抛出另一个* .spec.js文件来运行完全相同的命令,但它失败了。

错误

/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113
  var template = new Error(this.message);
                 ^
NoSuchElementError: no such element
  (Session info: chrome=44.0.2403.107)
  (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.16.0-44-generic x86_64)
    at new bot.Error (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113:18)
    at Object.bot.response.checkResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
    at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:377:20
    at [object Object].promise.ControlFlow.runInFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
    at [object Object].promise.Callback_.goog.defineClass.notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
    at [object Object].promise.Promise.notify_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)
    at Array.forEach (native)
    at Object.goog.array.forEach (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/array/array.js:203:43)
    at [object Object].promise.Promise.notifyAll_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:552:16)
    at [object Object].goog.async.run.processWorkQueue [as _onTimeout] (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:125:21)
From: Task: WebElement.sendKeys()
    at [object Object].webdriver.WebDriver.schedule (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:360:15)
    at [object Object].webdriver.WebElement.schedule_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1815:23)
    at [object Object].webdriver.WebElement.sendKeys (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1986:17)
    at Object.exports.loginToPage (/home/allison/Devspace/client/test/e2e/helperFunctions.js:11:63)
    at Suite.<anonymous> (/home/allison/Devspace/client/test/e2e/authenticated/students.spec.js:41:21)
    at addSpecsToSuite (/usr/local/lib/node_modules/protractor/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:743:25)
    at Env.describe (/usr/local/lib/node_modules/protractor/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:713:7)
    at jasmineInterface.describe (/usr/local/lib/node_modules/protractor/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:3219:18)
    at Object.<anonymous> (/home/allison/Devspace/client/test/e2e/authenticated/students.spec.js:1:63)
    at Module._compile (module.js:456:26)

authenticated.conf.js

'use strict'

// An example configuration file.
exports.config = {
  directConnect: true,

  chromeOnly: true,

  onPrepare: function() {
    //browser.driver.get(env.baseUrl)
    protractor.helper = require('./helperFunctions.js');

  },


  baseUrl: 'http://localhost:3000/',

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Framework to use. Jasmine 2 is recommended.
  framework: 'jasmine2',

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: [
    'authenticated/*.spec.js',
    'invoices/*.spec.js',
    'partners/*.spec.js',
    'quotes/*.spec.js',
    'settings/*.spec.js',
  ],

  // to specify a single FILE to run, run "protractor authenticated.conf.js --specs file.spec.js"
  // to specify ONE suite to run, type "protractor authenticated.conf.js --suite quotes"
  suites: {
    quotes: 'quotes/*.spec.js',
    students: 'authenticated/*.spec.js',
    invoices: 'invoices/*.spec.js',  
    settings: 'settings/*.spec.js',
    partners: './partners/*.spec.js'
  },

  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    defaultTimeoutInterval: 240000,
    showColors: true
  },

  allScriptsTimeout: 50000, //takes a while to login and load STudent page

};

students.spec.js摘录

  protractor.helper.loginToPage();

  var expected = protractor.ExpectedConditions;
  var newStudentUrl = "";

  it('should show new student in listings when the new student form is filled and Save button is clicked', function() {
    browser.get('/en/student/listing/509');

    ...

helperFunctions.js

exports.loginToPage = function(url) {
    browser.driver.get('http://localhost:3000/');
    browser.waitForAngular();

    browser.driver.findElement(by.css('input[name="email"]')).sendKeys('user@something.com');
    browser.driver.findElement(by.css('input[name="password"]')).sendKeys('password');
    browser.driver.findElement(by.css('button[type="submit"]')).click();

    return browser.driver.wait(function() {
      return browser.driver.getCurrentUrl().then(function(url) {
        return /\/en\/$/.test(url);
      });
    }, 15000);

};

1 个答案:

答案 0 :(得分:1)

我最近看到了很多这样的行为,we're not alone。似乎那里有一个错误。我有随机失败的测试。我已经尝试了一切我能想到的东西来修复它们,但唯一可行的方法是放置一个简短的browser.sleep来帮助轻推等待:)

尝试在提交按钮browser.sleep(420)之后或click()来电之前添加getCurrentUrl()。 (420毫秒,因为它很有趣:)但有些事情对我来说很有用。)

虽然不是解决方案(使用browser.sleep会伤害我的灵魂),但现在这是一种解决方法。比片状测试更好。