如何使用量角器js测试非角度位置?

时间:2021-08-02 01:23:41

I've been looking all around the internet but there doesn't seem to be any reliable resources or examples that test non-angular websites with protractor JS.

我一直在寻找互联网,但似乎没有任何可靠的资源或例子,用量角器JS测试非角度网站。

Currently, my conf file looks like this

目前,我的conf文件看起来像这样

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

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

  };

And my wikipedia-test-spec.js looks like this

而我的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();
    });

});

When I run protractor conf.js, I get a type error undefined is not a function and my spec fails.

当我运行量角器conf.js时,我得到一个类型错误undefined不是一个函数,我的规范失败了。

UPDATE:

更新:

Entire stack trace of the error

整个堆栈跟踪错误

 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)

1 个解决方案

#1


4  

isPresent() function is available on the ElementFinder instance, which is the result of element() call. You might need to use driver.isElementPresent() here:

isPresent()函数在ElementFinder实例上可用,它是element()调用的结果。您可能需要在此处使用driver.isElementPresent():

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

with:

有:

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

Or, you can also try with element():

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

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

Note that you would also need to turn the synchronization with AngularJS off:

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

browser.ignoreSynchronization = true;

Also see:

另见:

#1


4  

isPresent() function is available on the ElementFinder instance, which is the result of element() call. You might need to use driver.isElementPresent() here:

isPresent()函数在ElementFinder实例上可用,它是element()调用的结果。您可能需要在此处使用driver.isElementPresent():

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

with:

有:

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

Or, you can also try with element():

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

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

Note that you would also need to turn the synchronization with AngularJS off:

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

browser.ignoreSynchronization = true;

Also see:

另见: