整合Travis / Sauce Labs时,“无法找到Angular”

时间:2015-03-08 17:24:32

标签: angularjs protractor travis-ci saucelabs

我正在努力让Travis CI使用Sauce Labs运行Protractor测试。隧道工作正常,我的Express服务器明显启动并保持在http://localhost:9000,但我的Protractor测试很快失败,错误为Error: Angular could not be found on the page http://localhost:9000/ : retries looking for angular exceeded。互联网上的所有建议通常都涉及不使用Angular 1.0(使用1.3),延长超时(这样做),或强制Protractor查看<html> ng-app指令(这样做)。我没有想法。

相关配置:

protractor.conf.js

exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
baseUrl: 'http://localhost:9000',

specs: ['e2e/**/*.spec.js'],
framework: 'jasmine',
maxSessions: 1,
allScriptsTimeout: 30000,
rootElement: 'html',
multiCapabilities: [
    {'browserName': 'chrome'},
    {'browserName': 'firefox'},
    {'name': 'diplomacy'},
    {'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER ? process.env.TRAVIS_JOB_NUMBER : null},
    {'build': process.env.TRAVIS_BUILD_NUMBER ? process.env.TRAVIS_BUILD_NUMBER : null}
],
jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 360000,
    includeStackTrace: true
}
}

main.spec.js

'use strict';

describe('Home page', function() {
    var page;

    beforeEach(function() {
        browser.get(browser.baseUrl);
    });

    it('should pass', function() {
         expect(true).toBe(true);
    });
});

特拉维斯日志

转到here查看完整日志。亮点:

Extracting Sauce Connect
Waiting for Sauce Connect readyfile
08 Mar 16:30:00 - Sauce Connect 4.3.6, build 1628 8a5c837
08 Mar 16:30:00 - Using CA certificate bundle /etc/ssl/certs/ca-certificates.crt.
08 Mar 16:30:00 - Starting up; pid 3519
08 Mar 16:30:00 - Command line arguments: sc-4.3.6-linux//bin/sc -i 42.1 -f sauce-connect-ready-21801 -l /home/travis/sauce-connect.log
08 Mar 16:30:00 - Using no proxy for connecting to Sauce Labs REST API.
08 Mar 16:30:00 - Resolving saucelabs.com to 162.222.73.28 took 17 ms.
08 Mar 16:30:01 - Started scproxy on port 37246.
08 Mar 16:30:01 - Please wait for 'you may start your tests' to start your tests.
08 Mar 16:30:01 - Starting secure remote tunnel VM...
08 Mar 16:30:11 - Secure remote tunnel VM provisioned.
08 Mar 16:30:11 - Tunnel ID: 3cc5fd5b59984957831d125617c7d4f6
08 Mar 16:30:11 - Secure remote tunnel VM is now: booting
08 Mar 16:30:14 - Secure remote tunnel VM is now: running
08 Mar 16:30:14 - Remote tunnel host is: maki76159.miso.saucelabs.com
08 Mar 16:30:14 - Using no proxy for connecting to tunnel VM.
08 Mar 16:30:14 - Resolving maki76159.miso.saucelabs.com to 162.222.76.159 took 48 ms.
08 Mar 16:30:14 - Starting Selenium listener...
08 Mar 16:30:14 - Establishing secure TLS connection to tunnel...
08 Mar 16:30:14 - Selenium listener started on port 4445.
08 Mar 16:30:16 - Sauce Connect is up, you may start your tests.
08 Mar 16:30:16 - Connection established.

[单元测试......全部通过!]

[chrome #1] PID: 3621
[chrome #1] Specs: /home/travis/build/spamguy/diplomacy/e2e/main/main.spec.js
[chrome #1] 
[chrome #1] Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[chrome #1] [31mF[0m
[chrome #1] 
[chrome #1] Failures:
[chrome #1] 
[chrome #1]   1) Home page should pass
[chrome #1]    Message:
[chrome #1]      [31mError: Angular could not be found on the page http://localhost:9000/ : retries looking for angular exceeded[0m
[chrome #1]    Stacktrace:
[chrome #1]      Error: Angular could not be found on the page http://localhost:9000/ : retries looking for angular exceeded
[chrome #1] ==== async task ====
[chrome #1] Protractor.get(http://localhost:9000/) - test for angular
[chrome #1]     at [object Object].<anonymous> (/home/travis/build/spamguy/diplomacy/e2e/main/main.spec.js:7:13)
[chrome #1] ==== async task ====
[chrome #1] Asynchronous test function: beforeEach()
[chrome #1] Error
[chrome #1]     at [object Object].<anonymous> (/home/travis/build/spamguy/diplomacy/e2e/main/main.spec.js:6:3)
[chrome #1]     at Object.<anonymous> (/home/travis/build/spamguy/diplomacy/e2e/main/main.spec.js:3:1)
[chrome #1] 
[chrome #1] Finished in 11.877 seconds
[chrome #1] [31m1 test, 2 assertions, 1 failure
[0m[chrome #1] 
[chrome #1] SauceLabs results available at http://saucelabs.com/jobs/c0eed61d95044f77b200a7b21d2443a3

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

[另外两个WebDriver实例失败并出现类似错误]

2 个答案:

答案 0 :(得分:1)

FWIW,我最终让一切正常。我没有“一个修复”,所以我无法轻易澄清解决方案。以下文件为from my repository with which I set up continuous integration

量角器-travis.conf.js

exports.config = {
    // sauce plz
    sauceUser: process.env.SAUCE_USERNAME,
    sauceKey: process.env.SAUCE_ACCESS_KEY,
    baseUrl: 'http://localhost',

    specs: ['e2e/**/*.po.js', 'e2e/**/*.spec.js'],
    framework: 'jasmine',
    maxSessions: 1,
    allScriptsTimeout: 40000,
    getPageTimeout: 40000,
    rootElement: 'html',
    multiCapabilities: [
        capabilitiesForBrowser('chrome', '41'),
        capabilitiesForBrowser('firefox'),
        capabilitiesForBrowser('safari')
    ],
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 360000,
        includeStackTrace: true
    }
};

function capabilitiesForBrowser(browserName, browserVersion) {
    var capabilities = {
        'browserName': browserName,
        'build': process.env.TRAVIS_BUILD_NUMBER,
        'name': 'dipl.io'
    };
    if (browserVersion)
        capabilities.version = browserVersion;

    return capabilities;
}

Gruntfile.js

protractor: {
        travis: {
            options: {
                configFile: 'protractor-travis.conf.js',
                args: {
                    sauceUser: process.env.SAUCE_USERNAME,
                    sauceKey: process.env.SAUCE_ACCESS_KEY
                }
            }
        },
        local: {
            options: {
                configFile: 'protractor-local.conf.js'
                //,debug: true
            }
        }
    }

.travis.yml

language: node_js
node_js:
  - '0.12'
services:
    - mongodb
env:
  global:
    - secure: ioYHs4gjuL9iuwxamtKCkERvvSiBlAgxhLZ1Ry4xrZhNWe3e4pett3249hWovDYzG/eEHTA20/NDvZ1JIMYODFzY4gURVHNtUkoYNokLSDguTH1OPXGMmtQzJGersxYQOjRj3gSss7Z0joUrcfPQJsG1Vt0eHR/ewN7Qbm8NBn0=
    - secure: NH3WbHM2Ir95csdWAdd7/ISYVvnYFQe7Rv4rCoYu9V6V2M9AzlARYTAvBqoK7PdD/RV0KR41t6OVeUxBVhuzT26NvBVZVyLcvfjK29AoKCDCU7VD7nQa/RQ9KyDr5DAHfyQQ5AQMhsla5qPTaFZb82F83lL44nDzrvYzE8CEaGw=

before_install:
    - npm install -g bower
    - bower install
    - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
    - git submodule update --init --recursive
    - npm install -g grunt-cli

script:
    - grunt test:protractor-travis

答案 1 :(得分:0)

我在这里遇到同样的问题。除了这里有区别之外:

当我手动启动SauceConnect隧道时,如下所述: https://docs.saucelabs.com/reference/sauce-connect/#when-should-i-use-sauce-connect-

然后一切顺利,我的构建通过。

但我不想每次都要手动启动SauceConnect,我希望在构建过程中自动启动它。所以我按照这里的说明更新了travis.yml文件:

http://docs.travis-ci.com/user/sauce-connect/

在这种情况下,隧道会自动打开。这里有一些日志,太长时间无法粘贴所有内容,但我可以向您保证隧道已打开。

    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge, chrome=1">
        <title>my site</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <link rel="stylesheet" href="css/bootstrap.css">
        <link rel="stylesheet" href="css/bootstrap-modal-carousel.min.css">
        <link rel="stylesheet" href="css/main.css">
        <link rel="stylesheet" href="css/mycss.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/bootstrap.min.js">
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
    </head>
<body>
            <div class="row row-top">
                <div class="col-sm-8 col-md-offset-2">                 
                  <nav class="navbar navbar-default">
                      <div class="container-fluid">
                        <!-- Brand and toggle get grouped for better mobile display -->
                        <div class="navbar-header">
                          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                          </button>
                          <a class="navbar-brand" href="/home.html">my brand goes here and here</a>

                        </div>

                        <!-- Collect the nav links, forms, and other content for toggling -->
                        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                          <ul class="nav navbar-nav navbar-right">
                            <li><a href="/projects.html">Projects </a></li>
                            <li><a href="/services.html">tab2</a></li>
                            <li><a href="/aboutus.html">tab3</a></li>
                            <li><a href="/contactus.html">tab4</a></li>
                          </ul>
                        </div><!-- /.navbar-collapse -->
                      </div><!-- /.container-fluid -->
                    </nav>
                </div>
            </div>  

...

@media (max-width: @screen-xs) {
        .navbar-brand {
        font-size:15px;
        }

}

@media (max-width: @screen-sm) {
            .navbar-brand {
        font-size:20px;
        }

}

@media (max-width: @screen-md) {
            .navbar-brand {
        font-size:30px;
        }

}
@media (max-width: @screen-lg) {
            .navbar-brand {
        font-size:50px;
        }

    } 

但是一旦打开连接,并且构建到达测试应该运行的程度,我会得到你在上面列出的相同Angular错误。