大量的試驗和錯誤之後,我終於有了這個工作:
點
文件的例子:
:
的測試是自動由圓使用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,這是不符合硒/ Nightwatch的當前版本兼容。 Chrome需要在circle.yaml
的pre
依賴關係進行更新:
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
的Circle docs忘記在Apache的conf文件中的一個重要棋子,你必須set the allow/deny rules for your webroot directory,端口也被更改爲使用默認端口80
:
<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>
然後,必須激活所有需要的Apache模塊,並加載你的conf到Apache中,使用circle.yaml:
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"
a2enmod
行爲PHP應用程序啓用必要的apache模塊重寫和標頭。
a2ensite
啓用配置文件和您的域。某些領域,如* .dev還需要添加一行到/etc/hosts
:
- sudo sh -c "echo 127.0.0.1 local.phpwebapp.dev >> /etc/hosts"
這是實現當圓Chrome瀏覽器是給錯誤ERR_ICANN_NAME_COLLISION
。通過Nightwatch打印source of the test page發現錯誤:
browser
.url("http://www.local.phpwebapp.dev")
.source(function (result){
// Source will be stored in result.value
console.log(result.value);
})