如何在CircleCI中运行Nightwatch测试?

时间:2017-04-17 20:57:05

标签: php apache testing nightwatch.js circleci

我试图在CircleCI中运行Nightwatch测试并且它有点像......噩梦

似乎CricleCI没有设置为PHP应用程序运行Web服务器。

CircleCI版Chrome浏览器~54与Nightwatch不兼容,后者要求> = ~55

CircleCI的Chrome无法找到我的local.webapp.dev域名,并提供错误ERR_ICANN_NAME_COLLISION

我已使用以下apache配置设置了Web服务器,该配置已根据CircleCI docs中的推荐版本进行了修改:

<VirtualHost *:80>
  LoadModule php5_module /opt/circleci/php/5.6.17/libexec/apache2/libphp5.so

  DocumentRoot /home/ubuntu/phpwebapp
  ServerName local.webapp.dev
  <FilesMatch \.php$>
    SetHandler application/x-httpd-php
  </FilesMatch>
</VirtualHost>

1 个答案:

答案 0 :(得分:1)

经过多次反复试验,我终于有了这个工作:

文件示例:

Circle使用package.json

自动运行测试
"test": "./node_modules/.bin/nightwatch --env circleci"

这会从您的Nightwatch.json

中选择并运行测试
"circleci" : {
  "output_folder" : "${CIRCLE_TEST_REPORTS}",
  "launch_url" : "http://local.phpwebapp.dev",
  "selenium_host" : "localhost",
  "selenium_port" : 4444,
  "screenshots" : {
    "enabled" : false,
    "path" : ""
  },
  "desiredCapabilities" : {
    "browserName" : "chrome",
    "marionette": true
  }
}

CircleCI计算机使用的旧版Chrome与当前版本的Selenium / Nightwatch不兼容。 Chrome需要在pre的{​​{1}}依赖关系中进行更新:

circle.yaml

Circle docs忘记了apache conf文件中的一个重要部分,你必须set the allow/deny rules for your webroot directory,端口也被更改为使用默认端口dependencies: pre: # Update Google Chrome. - google-chrome --version - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - - sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb stable main" >> /etc/apt/sources.list.d/google.list' - sudo apt-get update - sudo apt-get --only-upgrade install google-chrome-stable - google-chrome --version

80

然后你必须使用circle.yaml激活所有必需的Apache模块并将你的conf加载到Apache中:

<VirtualHost *:80>
  LoadModule php5_module /opt/circleci/php/5.6.17/libexec/apache2/libphp5.so

  DocumentRoot /home/ubuntu/phpwebapp
  ServerName local.phpwebapp.dev
  <FilesMatch \.php$>
    SetHandler application/x-httpd-php
  </FilesMatch>
  <Directory /home/ubuntu/phpwebapp>
    AllowOverride all
    Require all granted
  </Directory>
</VirtualHost>

dependencies: ... post: # circle seems to expect this but doesnt install it - sudo apt-get install libapache2-mod-php5 # copy apache config file - sudo cp ~/phpwebapp/circleApache.conf /etc/apache2/sites-available # give phpwebapp to apache - sudo chown -R www-data:www-data ~/phpwebapp - sudo a2enmod rewrite - sudo a2enmod headers - sudo a2ensite circleApache # DocumentRoot doesnt work, so symlinking instead - sudo rm -r /var/www/html - sudo ln -s /home/ubuntu/phpwebapp /var/www/html - ls /var/www/html - sudo service apache2 restart # add local.phpwebapp.dev to /etc/hosts - sudo sh -c "echo 127.0.0.1 local.phpwebapp.dev >> /etc/hosts" 行启用了必要的apache模块重写和PHP应用程序的标头。

a2enmod启用配置文件和您的域。某些域名(如* .dev)也需要在a2ensite添加一行:

/etc/hosts

这是在Circle Chrome浏览器发出错误- sudo sh -c "echo 127.0.0.1 local.phpwebapp.dev >> /etc/hosts"时实现的。通过Nightwatch打印source of the test page来发现错误:

ERR_ICANN_NAME_COLLISION