如何使用量角器 js 测试非 angular 站点?

How do I test a non-angular site with protractor js?

我一直在互联网上四处寻找,但似乎没有任何可靠的资源或示例可以使用量角器 JS 测试非 angular 网站。

目前,我的配置文件如下所示

 exports.config = {
  seleniumServerJar: 'webdriver/selenium-server-standalone-2.48.2.jar',
  specs: [
    'wikipedia-test-spec.js'
  ], 
  chromeDriver : 'webdriver/chromedriver.exe',

  multiCapabilities: [
    {
        'browserName': 'chrome'
    }
  ],

  };

我的 wikipedia-test-spec.js 看起来像这样

describe("Tests a wikipedia page", function(){
     it('Should check if table exists', function(){
            browser.get('https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population');
            var table = browser.driver.findElement(by.name('table'));
            expect(table.isPresent()).toBeTruthy();
    });

});

当我 运行 protractor conf.js 时,我收到类型错误 undefined is not a function 并且我的规范失败。

更新:

错误的完整堆栈跟踪

 Stacktrace:
     TypeError: undefined is not a function
    at [object Object].<anonymous> (C:\nodejs\CGAngularTest\wikipedia-test-spec.js:5:26)
    at C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14
    at goog.async.run.processWorkQueue (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
From: Task: Asynchronous test function: it()
    at [object Object].<anonymous> (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33)
    at [object Object].<anonymous> (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37)
    at [object Object].jasmine.Block.execute (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17)
    at [object Object].jasmine.Queue.next_ (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
    at [object Object]._onTimeout (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
Error
    at [object Object].<anonymous> (C:\nodejs\CGAngularTest\wikipedia-test-spec.js:2:3)
    at [object Object].jasmine.Env.describe_ (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21)
    at [object Object].jasmine.Env.describe (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
    at describe (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
    at Object.<anonymous> (C:\nodejs\CGAngularTest\wikipedia-test-spec.js:1:63)

isPresent() functionElementFinder 实例上可用,这是 element() 调用的结果。您可能需要在此处使用 driver.isElementPresent()

var table = browser.driver.findElement(by.name('table'));
expect(table.isPresent()).toBeTruthy();

与:

var table = browser.driver.findElement(by.name('table'));
expect(browser.driver.isElementPresent(table)).toBeTruthy();

或者,您也可以尝试 element():

var table = element(by.name('table'));
expect(table.isPresent()).toBeTruthy();

请注意,您还需要关闭与 AngularJS 的同步:

browser.ignoreSynchronization = true;

另见: