duanjue6575 2017-04-17 20:57
浏览 63
已采纳

如何在CircleCI中运行Nightwatch测试?

I am trying to get Nightwatch tests running in CircleCI and it has been a bit of a ...nightmare

It seems that CricleCI is not set up to run a webserver for a PHP app.

CircleCI version of the Chrome browser ~54 is not compatible with Nightwatch, which is asking for >= ~55

CircleCI's Chrome cannot find my local.webapp.dev domain, and gives the error ERR_ICANN_NAME_COLLISION

I have setup the web server, using the following apache config, modified from the recommended version in the 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条回答 默认 最新

  • dq1685513999 2017-04-17 20:57
    关注

    After much trial and error, I finally have this working:

    File examples:

    The tests are run automatically by Circle using the package.json:

    "test": "./node_modules/.bin/nightwatch --env circleci"
    

    This picks up and runs the tests from your 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 machines are using an older version of Chrome which is not compatible with the current version of Selenium/Nightwatch. Chrome needs to be updated in the pre dependencies of circle.yaml:

    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
    

    The Circle docs forget an important piece in the apache conf file, you must set the allow/deny rules for your webroot directory, the port is also changed to use the default port 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>
    

    You must then activate all the required Apache modules and load your conf into Apache, using 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"
    

    The a2enmod lines enable the necesary apache modules rewrite and header for the PHP app.

    a2ensite enables the configuration file and your domain. Certain domains, like *.dev will also require adding a line to /etc/hosts:

    - sudo sh -c "echo 127.0.0.1 local.phpwebapp.dev >> /etc/hosts"

    This was realized when the Circle Chrome browser was giving the error ERR_ICANN_NAME_COLLISION. The error was uncovered by printing the source of the test page via Nightwatch:

    browser
        .url("http://www.local.phpwebapp.dev")
        .source(function (result){
            // Source will be stored in result.value
            console.log(result.value);
        })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了