I need to get the pagesource & then check whether the text "hello world" is absent in the pagesource.
I am trying the below method which is failing.
var page_source=browser.getPageSource().then(function (text){
expect(text).not.toContain("hello world");
});
Any suggestions ??
Error trace:
Stack:
Error: Failed expectation
at Object.<anonymous> (C:\Protractor\Testcases\test.js:56:38)
at C:\Protractor\node_modules\jasminewd2\index.js:110:25
at new ManagedPromise (C:\Protractor\node_modules\selenium-webdriver\lib\promise.js:1067:7)
at ControlFlow.promise (C:\Protractor\node_modules\selenium-webdriver\lib\promise.js:2396:12)
at schedulerExecute (C:\Protractor\node_modules\jasminewd2\index.js:95:18)
at TaskQueue.execute_ (C:\Protractor\node_modules\selenium-webdriver\lib\promise.js:2970:14)
at TaskQueue.executeNext_ (C:\Protractor\node_modules\selenium-webdriver\lib\promise.js:2953:27)
at asyncRun (C:\Protractor\node_modules\selenium-webdriver\lib\promise.js:2860:25)
at C:\Protractor\node_modules\selenium-webdriver\lib\promise.js:676:7
1 spec, 1 failure
Finished in 85.814 seconds
[18:02:43] I/launcher - 0 instance(s) of WebDriver still running
[18:02:43] I/launcher - internet explorerANY #01 failed 1 test(s)
[18:02:43] I/launcher - overall: 1 failed spec(s)
[18:02:43] E/launcher - Process exited with error code 1
Specs file:
specs: ['./Testcases/test.js'],
Couple of Suggestions.
expect(browser.getPageSource()).not.toContain("hello world")
And yes, what you are doing is correct- The Rest of it - I mean the Jasmine assertion and use of
not
is correct and it should work as expectedTry this regular expression way for your requirement.
Examples:
FYI - toContain()- for finding an item in an Array.
Example:
If you use app based on Angular you shuold do something strange.
Due to https://github.com/angular/protractor/blob/master/docs/timeouts.md#how-to-disable-waiting-for-angular you should disable waiting for Angular itself.
Example: