2017-08-23 18 views
2

我已經VS代碼配置了這樣的量角器調試調試任務:如何用VS代碼調試器記錄量角器文本元素?

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "type": "node", 
      "request": "launch", 
      "name": "Debug Tests (Local)", 
      "program": "${workspaceRoot}/node_modules/protractor/bin/protractor", 
      "args": [ 
       "${workspaceRoot}/config/protractor/protractor.conf.override.js" 
      ] 
     } 
    ] 
} 

說我有這個測試:

it('description', function() { 
    expect(this.myPageObject.title.getText()).toEqual('My PO Title'); 
}) 

這一切工作正常,但現在我特林調試這與VS代碼。我給自己定的expect線斷點和調試工作本身就好了。但是現在我想打印(到調試控制檯)this.myPageObject.title.getText()的值。

我知道getText和大多數其他量角器方法返回的承諾,我需要解決這些問題,但我不知道怎麼樣。以下是我所嘗試的:

this.myPageObject.title.getText() 
ElementFinder {browser_: ProtractorBrowser, then: (fn, errorFn) => { … }, parentElementArrayFinder: ElementArrayFinder …} 

this.myPageObject.title.getText().then(console.log) 
ManagedPromise {flow_: ControlFlow, stack_: null, parent_: ManagedPromise …} 

我錯過了什麼?

回答

0

不幸的是沒有很好的解決方案在我腦海

1)儘量把斷點進入回調 -

let titleText = this.myPageObject.title.getText().then(text => { 
    return text // Breakpoint here, so you can observe text variable in debug panel 
}) 
expect(titleText).toEqual('My PO Title'); 

2)您可以嘗試使用> protractor --elementExplorer終端命令調試,這在開始量角器交互更多,在那裏你可以觀察到你的行動一步一步

3)你可以嘗試使用await this.myPageObject.title.getText()在代碼調試終端的斷點。沒有嘗試過,但可能有效。

這是無極經理的一個問題 - 很難調試,所以這就是爲什麼它不久將被取消。更多信息:http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/promise.htmlhttps://github.com/SeleniumHQ/selenium/issues/2969

+0

1)IMO是違背了使用調試器,如果我不得不改變我的代碼,所有的時間只是爲了調試的全部目的。 2)我似乎沒有這種方式訪問​​我的測試環境。 3)沒有工作,「等待」沒有定義。 –