使用Xvfb和firefox在docker容器中无头地运行mocha测试时出错

时间:2016-01-05 16:37:19

标签: ubuntu firefox docker headless xvfb

我目前正在使用运行ubuntu映像的docker容器中工作。

这些是我用来安装Xvfb,firefox和Nodejs的一系列命令:

apt-get update

apt-get install -y xorg xvfb firefox dbus-x11 xfonts-100dpi xfonts-75dpi xfonts-cyrillic

apt-get install -y python gcc make g++ wget

wget https://nodejs.org/download/rc/v4.0.0-rc.1/node-v4.0.0-rc.1.tar.gz

tar -zxvf node-v4.0.0-rc.1.tar.gz
cd node-v4.0.0-rc.1

./configure

make install

安装并确保Node,npm和Xvfb正常工作后,我尝试在firefox无头上运行我的一些测试。

以下是我用来运行Xvfb和我的测试脚本的命令(我编写了一个调用mocha和相应测试的npm脚本):

xvfb-run npm run l-2361:spec

这是我的输出:

> ui-tests@1.0.0 l-2361:spec /go/src/bitbucket.org/companyName/platform/qe
> npm run env-local mocha test/admin/dashboard/adminUser/pdvi-2361.js -- --reporter spec --slow 0


> ui-tests@1.0.0 env-local /go/src/bitbucket.org/companyName/platform/qe
> env envVar='local' "mocha" "test/admin/dashboard/adminUser/pdvi-2361.js" "--reporter" "spec" "--slow" "0"



  Admin Tests - Role Admin User
    1) "before all" hook
    2) "after all" hook


  0 passing (29s)
  2 failing

  1) Admin Tests - Role Admin User "before all" hook:
     Uncaught NoSuchElementError: Unable to locate element: {"method":"css selector","selector":"input[name=\"email\"]"}
      at new bot.Error (node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
      at Object.bot.response.checkResponse (node_modules/selenium-webdriver/lib/atoms/response.js:109:9)
      at node_modules/selenium-webdriver/lib/webdriver/webdriver.js:379:20
      at promise.Promise.goog.defineClass.invokeCallback_ (node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
      at promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
      at goog.async.run.processWorkQueue (node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
  From: Task: WebElement.sendKeys()
      at webdriver.WebDriver.schedule (node_modules/selenium-webdriver/lib/webdriver/webdriver.js:362:15)
      at webdriver.WebElement.schedule_ (node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1817:23)
      at webdriver.WebElement.sendKeys (node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1988:17)
      at AdminLogin.fillEmail (pageObject/admin/login/index.js:32:21)
      at Context.<anonymous> (test/admin/dashboard/adminUser/pdvi-2361.js:27:16)

  2) Admin Tests - Role Admin User "after all" hook:
     EBUSY: resource busy or locked, unlink '/go/src/bitbucket.org/companyName/platform/qe/tmp-31175duruauo/amd64/.nfs00000000007d601300000004'
  Error: EBUSY: resource busy or locked, unlink 'tmp-31175duruauo/amd64/.nfs00000000007d601300000004'
      at Error (native)
  From: Task: WebDriver.call(function)
      at webdriver.WebDriver.call (node_modules/selenium-webdriver/lib/webdriver/webdriver.js:642:15)
      at Driver.quit (node_modules/selenium-webdriver/firefox/index.js:296:15)
      at Context.<anonymous> (test/admin/dashboard/adminUser/pdvi-2361.js:35:24)

这是我的测试文件,我将selenium函数/方法放在多个页面对象中。

var driver = require('selenium-webdriver');
var sinon = require('sinon');
var chai = require('chai');
var sinonChai = require("sinon-chai");
var expect = chai.expect;
var should = chai.should;
var config = require('../../../../variables');
var AdminLogin = require('../../../../pageObject/admin/login/index.js');
var HeaderProfile = require('../../../../pageObject/admin/login/common/headerProfile/index.js');
var AccountSettings = require('../../../../pageObject/admin/login/accountSettings/index.js');

chai.use(require('chai-as-promised'));
chai.use(sinonChai);

describe('Admin Tests - Role Admin User', function() {
  var adminVar = process.env.envVar;
  var login = config[adminVar].adminSignin;
  var user = config[adminVar].role.adminUser.name;
  var email = config[adminVar].role.adminUser.email;
  var pw = config[adminVar].role.adminUser.password;
  before(function() {
    this.timeout(50000);
    this.driver = new driver.Builder().withCapabilities(driver.Capabilities.firefox()).build();
    this.driver.get(login);

    var adminLogin = new AdminLogin(this.driver);
    adminLogin.fillEmail(email);
    adminLogin.fillPassword(pw);
    adminLogin.signin();

    return this.driver.manage().timeouts().implicitlyWait(250);
  });

  after(function() {
    return this.driver.quit();
  });

  describe('would like to', function() {
    it('verify they have global access', function() {
      var headerProfile = new HeaderProfile(this.driver);
      return expect(headerProfile.getName()).to.eventually.equal(user);
    });
  });

  describe('would like to', function() {
    before(function() {
      var headerProfile = new HeaderProfile(this.driver);
      headerProfile.clickButton();
      return headerProfile.accountSettings();
    });

    it('go to account settings', function() {
      var acctSettings = new AccountSettings(this.driver);
      return expect(acctSettings.titleText()).to.eventually.equal('Account Settings');
    });
  });

});

pdvi-2361.js:35:24就是这个功能:

after(function() {
    return this.driver.quit();
  });

第一个错误是无法访问我想要测试的网页的结果,但我不太清楚第二个错误意味着什么。

尝试运行测试后,它创建了一个包含子文件夹的tmp文件夹

tmp-311175duruauo/
  amd64/
  extensions/
    fxdriver@googlecode.com/
      platform/
        WINNT_x86-msvc/
          components/
            imehandler.dll
      resource/
        modules/
          timer.js
          web-element-cache.js
  storage/
    permanent/
      chrome/
        .metadata
        idb/
          piupsah.files/
          piupsah.sqlite
          piupsah.sqlite-shm
          piupsh.sqlite-wal

timer.js只有100个LOC,而web-element-cache.js几乎是10,000个LOC。上面的错误没有引用这些文件,所以我猜它们与我的问题无关?

此tmp目录仅在我运行测试时创建,我将如何取消链接以及为什么需要取消链接?

0 个答案:

没有答案