angularjs - 使用 Protractor + Appium + SauceLabs

标签 angularjs node.js protractor appium saucelabs

我一直在尝试对移动 Protractor 测试进行自动化。 我阅读了网络上的大部分博客,我读到了这篇博客,它是 Appium 与 Saucelabs 的“官方”博客: https://docs.saucelabs.com/tutorials/appium/#mobile-web-application 我按照那里的说明进行操作,并将我的 config.js 文件配置为这样

var testName = 'Testing'; //Change Project's name here in order to be identified in BrowserStack

exports.config = {
    // The address of a running selenium server.
    seleniumAddress: 'http://bmsoko:[redacted]@ondemand.saucelabs.com:80/wd/hub',
    // Capabilities to be passed to the webdriver instance.
    multiCapabilities: [{
        name: testName,
        'appium-version': '1.4.0',
        'browserName': 'Android',
        'deviceName': 'Android Emulator',
        'deviceOrientation': 'portrait',
        'platform': 'Linux',
        'version': '5.1',
        username: 'bmsoko',
        accessKey: '[redacted]'
    }],

    // Spec patterns are relative to the current working directly when
    // protractor is called.

    suites: {
        mobile: './././specs/mobile.js'
    },

    // Maximum number of total browser sessions to run. Tests are queued in
    // sequence if number of browser sessions is limited by this parameter.
    // Use a number less than 1 to denote unlimited. Default is unlimited.
    maxSessions: 2,

    // protractor will save the test output in json format at this path.
    // The path is relative to the location of this config.
    resultJsonOutputFile: null,

    framework: 'jasmine2',

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 100000,
        realtimeFailure: true,
        showTiming: true,
        includeStackTrace: true,
        isVerbose: true,
        onComplete: null
    },

    onPrepare: function () {
        //browser.driver.manage().window().maximize();
        global.dvr = browser.driver; //variable to call selenium directly
        global.isAngularSite = function (flag) {
            browser.ignoreSynchronization = !flag; //This setup is to configure when testing non-angular pages
        };
        browser.manage().timeouts().implicitlyWait(10000);
        browser.getCapabilities().then(function (cap) {
            browserName = cap.caps_.browserName;
        });

    }

};

这是我在测试中尝试做的事情(我知道这不是一个很好的测试,我只是想测试 Appium 与我的 Angular 应用程序一起工作。):

it('User should see module 1s elements on the web page', function () {
   browser.sleep(6000); 
   browser.driver.findElement(by.css('.play__video'));
});

但是当我运行测试时,我不断收到 Android 错误:

编辑:我可以看到网页正在打开。

Stack: Error: Failed: {"message":"[$injector:modulerr] Failed to instantiate module p due to:\nError: [$injector:nomod] Module 'p' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.\nhttp://errors.angularjs.org/1.3.14/$injector/nomod?p0=p\n at http://WEBAPPLICATION.com/assets/javascripts/global.js:107:21272\n at http://WEBAPPLICATIONs.com/assets/javascripts/global.js:107:29604\n at t (http://WEBAPPLICATION.com/assets/javascripts/global.js:107:29176)\n

我也尝试过这种情况:

it('User should see module 1 s video start on the web page', function () {
    browser.wait(EC.visibilityOf(basePage.videoButtonModule1), 10000);
    basePage.videoButtonModule1.click();
    expect(basePage.videoContainerModule1.isDisplayed()).toBeTruthy();
});

但为此我收到上述错误以及以下消息:

Message: Failed: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability\nhttp://errors.angularjs.org/1.3.14/ng/test"

我做错了什么???请帮忙!!

编辑 2: 分享我在 iOS 上遇到的错误

New Landing page module verification --> User should see module 1 s video start on the web page Message: Failed: Angular could not be found on the page WEBAPP.com/ : angular never provided resumeBootstrap Stack: Error: Failed: Angular could not be found on the page WEBAPP.com/ : angular never provided resumeBootstrap at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:102:16 at [object Object].promise.ControlFlow.runInFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20) at [object Object].promise.Callback_.goog.defineClass.notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25) at [object Object].promise.Promise.notify_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)

最佳答案

我终于能够让它在我的测试中发挥作用,唯一能在酱料上发挥魔力的组合是

multiCapabilities: [
        {
            platformName: 'iOS',
            platformVersion: '7.1',
            browserName: '',
            app: 'safari',
            deviceName: 'iPhone Simulator',
            'appium-version': "1.4.0",
            username: '<USERNAME>',
            accessKey: '<KEY>'

        }
        ,
        {
            platformName: 'Android',
            platformVersion: '4.4',
            browserName: 'Browser',
            deviceName: 'Android Emulator',
            'appium-version': "1.4.0",
            username: '<USERNAME>',
            accessKey: '<KEY>'
        }


        ], 

除这些之外的其他组合将不起作用,至少对于我的应用程序来说是这样。

我已向 Protractor 团队对我的原始问题发表了评论,希望他们能够回答。

https://github.com/angular/protractor/issues/2247

关于angularjs - 使用 Protractor + Appium + SauceLabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787588/

相关文章:

javascript - 使用 javascript get 查询循环进入一个空数组

javascript - 在 Protractor angularjs 上指定了无效或非法的选择器错误

node.js - 在同一 nginx 服务器上使用 SSL 的两个 node.js 域 - 443 的重复监听选项

node.js - Node.js 10 的 TypeScript tsconfig 设置?

selenium-webdriver - 使用 Protractor 从表中收集数据的最有效方法是什么?

javascript - 测试选项卡导航顺序

javascript - 服务显示 Angular 未定义

javascript - Web服务调用期间Angularjs中的异常

javascript - 异步加载 AngularJS 应用程序

javascript - angularjs 指令不适用于动态内容