2016-10-01 6 views
5

私は、このテストがあります。簡単なテストが、無効なロケータ:-(

// import {by, element, browser} from "protractor"; 
describe('intro',() => { 
    beforeEach(() => { 
    browser.get(''); 
    }); 

it('should have multiple pages',() => { 
    let buttonOnward = element(by.linkText('Continue')); 
    expect(element.all(buttonOnward).count()).toBe(1); 
    }); 
}); 

そして、この結果を得るために

1) intro should have multiple pages 
    Message: 
    Failed: Invalid locator 
    Stack: 
    TypeError: Invalid locator 
     at Object.check [as checkedLocator] (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\by.js:267:9) 
     at WebDriver.findElements (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:919:18) 
     at C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\built\element.js:161:44 
     at ManagedPromise.invokeCallback_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14) 
     at TaskQueue.execute_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14) 
     at TaskQueue.executeNext_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21) 
     at asyncRun (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2775:27) 
     at C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7 
     at process._tickCallback (internal/process/next_tick.js:103:7) 
    From: Task: Run it("should have multiple pages") in control flow 
     at Object.<anonymous> (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:79:14) 
     at C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:16:5 
     at ManagedPromise.invokeCallback_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14) 
     at TaskQueue.execute_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14) 
     at TaskQueue.executeNext_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21) 
     at asyncRun (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2775:27) 
    From asynchronous test: 
    Error 
     at Suite.describe (C:\xampp\htdocs\test\intro_spec.ts:11:3) 
     at Object.<anonymous> (C:\xampp\htdocs\test\intro_spec.ts:2:1) 
     at Module._compile (module.js:556:32) 
     at Object.Module._extensions..js (module.js:565:10) 
     at Module.load (module.js:473:32) 
     at tryModuleLoad (module.js:432:12) 

1 spec, 1 failure 

そして、私は理由を知りません。その本当に簡単私がダウンロードしました。ジャスミンと、このファイルC:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\by.jsをチェックするためのタイピング

それのために定義された関数があります:。

The defined function in by.js

また、ドキュメントにもその機能が存在することが記載されています。あなたのアイデアを事前に

http://www.protractortest.org/#/api?view=ProtractorBy.prototype.buttonText

$ protractor --version 
Version 4.0.9 
$ npm -v 
3.10.8 
$ node -v 
v6.7.0 

ありがとう!

答えて

8

:あなたは、総ボタン数をカウントしたい場合は、ちょうどそのようなあなたのロケータを宣言する必要があります。主な問題は、byロケータの代わりにElementFinderelement()コールの結果)を使用していることです。今

let buttonOnward = element(by.linkText('Continue')); 

、あなたが今、ロケータの代わりにElementFinderである、buttonOnwardを使用している:buttonOnwardが定義されている方法を参照してください

当然のことながら、「無効なロケータになり、
expect(element.all(buttonOnward).count()).toBe(1); 

"エラー。あなたが代わりに "によって" ロケータを使用している意味は何


expect(element.all(by.linkText('Continue')).count()).toBe(1); 
5

あなたのエラーはlinkTextロケータとはまったく関係がありません。問題はexpect(element.all(buttonOnward).count()).toBe(1);です。これは無効なロケータです。もう少しGundersonの答え@拡張するには

let buttonOnward = element.all(by.linkText('Continue')); 
expect(buttonOnward.count()).toBe(1); 
1

私の場合は私がbrowser.driver.findElementを使用していました。つまり、私はSelenium APIを使用していました。しかし、Selenium APIは明らかにby.modelロケーターをサポートしていません。しかし、分度器 APIはby.model locatorのサポートが含まれず、そして私が代わりにelement機能を使用分度器 APIを使用する:

は動作しません。

//This would not work: 
//error E/launcher - Error: TypeError: Invalid locator 
browser.driver.findElement(by.model('login_form.email')) 

ワークス:

//But this works; note it uses the `element` function 
//instead of `browser.driver.findElement` 
element(by.model('login_form.email')) 

でも動作します。

//And this also works; note it uses `browser.driver.findElement` 
//But it passes a different locator; not `by.model`, but `by.id` 
browser.driver.findElement(by.id('#login_form_email')) 

注:'ng-model'を付けることによって

分度器by.modelロケータます最終的にcall a CSS querySelectorAll。分度器が角度を重視しているので、分度器はby.modelロケータ機能を追加するのが理にかなっています。どのように

"モデル" ロケータがnot listed among Selenium (Java) locators on this page

  • あるので、私はセレンがネイティブby.modelをサポートしていないと仮定していますIdを
  • 名前
  • のClassName
  • CSS
  • のXpath
  • op

Nor in this Pythonセレンのメソッドのリスト。

関連する問題