使用Jenkins进行量角器UI测试失败,在cmd上运行

时间:2016-01-27 09:51:44

标签: jenkins protractor

我在Windows Server上配置了Jenkins,用于夜间构建,编译等。和UI测试(E2E测试)自动化,我遇到了一些问题。 我们有一个在Chrome上运行的Web应用程序,需要Jenkins使用量角器(使用Selenium)运行这些测试。

通过Windows cmd控制台手动运行,测试成功完成。

-------这是控制台输出;

***C:\Jenkins\jobs\UI Automation\workspace> protractor e2e-tests/protractor.conf.js

Using ChromeDriver directly...

[launcher] Running 1 instances of WebDriver

WARNING - more than one element found for locator by.repeater("attachment in pos
t_item.attachments") - the first result will be used

.
Finished in 68.394 seconds

1 test, 8 assertions, 0 failures

[launcher] 0 instance(s) of WebDriver still running

[launcher] chrome #1 passed***

-----这是Jenkins运行的输出;

C:\Jenkins\jobs\UI Automation\workspace>protractor e2e-tests/protractor.conf.js  
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
WARNING - more than one element found for locator by.repeater("attachment in post_item.attachments") - the first result will be used
[31mF[0m
Failures:
  1) new_message_with_attachment should send new message with attachment
   Message:
     [31mElementNotVisibleError: element not visible
  (Session info: chrome=47.0.2526.111)
  (Driver info: chromedriver=2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29),platform=Windows NT 6.0 SP2 x86_64)[0m
   Stacktrace:
     ElementNotVisibleError: element not visible
  (Session info: chrome=47.0.2526.111)
  (Driver info: chromedriver=2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29),platform=Windows NT 6.0 SP2 x86_64)
    at new bot.Error (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
    at Object.bot.response.checkResponse (C:\Users\x\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:106:9)
    at C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:362:20
    at C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
    at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1654:20)
    at notify (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:465:12)
    at notifyAll (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:442:7)
    at resolve (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:420:7)
    at [object Object].fulfill (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:535:5)
    at C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1520:10
==== async task ====
WebElement.click()
    at [object Object].webdriver.WebDriver.schedule (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:345:15)
    at [object Object].webdriver.WebElement.schedule_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:1727:23)
    at [object Object].webdriver.WebElement.click (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:1832:15)
    at actionFn (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\lib\element.js:75:32)
    at C:\Users\X\AppData\Roaming\npm\node_modules\protractor\lib\element.js:393:17
    at Array.forEach (native)
    at actionResults.getWebElements.then.then.e.stack (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\lib\element.js:392:9)
    at C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
    at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1654:20)
==== async task ====
Asynchronous test function: it()
    at [object Object].<anonymous> (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33)
    at [object Object].<anonymous> (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37)
    at [object Object].jasmine.Block.execute (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17)
    at [object Object].jasmine.Queue.next_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
    at [object Object]._onTimeout (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
Error
    at [object Object].ElementArrayFinder.applyAction_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\lib\element.js:389:21)
    at [object Object].self.(anonymous function) [as click] (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\lib\element.js:77:19)
    at [object Object].self.(anonymous function) [as click] (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\lib\element.js:697:11)
    at [object Object].<anonymous> (C:\Jenkins\jobs\UI Automation\workspace\e2e-tests\new_message_with_attachment.js:223:62)
    at C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14
    at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1654:20)
    at [object Object].webdriver.promise.ControlFlow.runEventLoop_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1518:8)
Error
    at [object Object].<anonymous> (C:\Jenkins\jobs\UI Automation\workspace\e2e-tests\new_message_with_attachment.js:76:3)
    at [object Object].jasmine.Env.describe_ (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21)
    at [object Object].jasmine.Env.describe (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
    at describe (C:\Users\X\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
    at Object.<anonymous> (C:\Jenkins\jobs\UI Automation\workspace\e2e-tests\new_message_with_attachment.js:75:1)
Finished in 59.756 seconds
[31m1 test, 8 assertions, 2 failures
[0m
[launcher] 0 instance(s) of WebDriver still running
Build step 'Execute Windows batch command' marked build as failure
Discard old builds...
Sending e-mails to: me@home.com
Finished: FAILURE*

-------这是protractor.conf.js;

*exports.config = {
  allScriptsTimeout: 20000,
  specs: [
    'new_message_with_attachment.js',
  ],

  capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
    prefs: {'profile.managed_default_content_settings.notifications': 1}},
  shardTestFiles: true,
    maxSessions: 1

  },

  directConnect: true,
  jasmineNodeOpts: {
    defaultTimeoutInterval: 1000000
  }
};*

有何评论?

1 个答案:

答案 0 :(得分:0)

在将Protractor与Jenkins CI集成时,曾经发生过一次。所以根据你的问题,我会提出一些有助于提高e2e测试稳定性的建议。

因为看起来你不只是在这里遇到一个问题。我相信这会解决你的一些问题,但可能无法解决所有问题。

  

和“未找到元素”之类的错误很可能是因为未完成的网页安装...

     

......每次运行都会遇到不同的错误

这是量角器最常见的问题,有很多原因导致这种情况发生。但幸运的是,可以通过与Page Object结合的非常简单的方法来避免。

这是页面对象:

var MyPage = function () {

    // SET ng-view or ui-view
    this.view = $('.view');

    // SET interactable components
    this.button = element(by.css('button'));

};

MyPage.prototype.get = function () {
    browser.setLocation('myRoute/something');
};

MyPage.prototype.waitForPresent = function() {
    var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(this.button), 10000);
};

在您的测试套件/规范中:

it("should test something", function() {
    var page = new MyPage();
    page.get();

    browser.waitForAngular();
    page.waitForPresent();

    page.button.click();
});

这里的技巧是使用预期条件并为页面对象waitForPresent编写原型,等待组件显示。选择一个您认为它将是您在视图/页面上呈现的最后一个。 (注意:您不需要使用页面对象,但是当您进行更大规模的套件时,这将非常难以管理)

  

但测试运行速度非常快,而且“找不到元素”等错误很可能是因为网页安装未完成。有时它甚至可以输入一些缺少字符的登录用户名。

看起来你确实拥有非常好的资源(CPU和RAM),但是你说有时它在登录时遗漏了一些字符。这意味着你仍然缺乏资源,而且怀疑你的图形是资源。图形资源几乎缺少所有服务器,因为它并不总是需要渲染。为了解决这个问题,没有代码调整,技巧或解决方法可以使用。您必须至少尝试其中任何一个(或两者兼有):

  • 离开去进行无头测试。因为渲染浏览器很重。 (使用Chrome或FireFox,因为不建议将PhantomJS用于量角器)
  • 尝试增加图片资源。

编辑:github Calling element.sendKeys() seems to not send all the keys上存在一个问题,它首先怀疑旧版本的Webdriver。但最近使用最新版Webdriver的人也得到了它。不明原因,但我非常怀疑这是由于缺乏某种资源。无论如何,这只是为了你的信息。希望它有所帮助:)