Parsing getText() return in JavaScript
See original GitHub issueDear Protractor Community,
Thank you for the excellent software. I want to parse http://baconipsum.com/ then take the returned generated meaty text and slice it thinner in protractor before inserting it into my app (for savory filler content). The test below works well, but if I try to convert the return of getText() as a string it comes back empty or as a string that just says ‘object’. For example, if I add:
This works:
'use strict';
describe('Visiting the butcher', function() {
it('should get meat', function() {
var ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;
var driver = ptor.driver;
driver.get("http://baconipsum.com/api/?type=all-meat&sentences=1&start-with-lorem=1");
var meat = ""
meat = driver.getPageSource();
expect(meat).toContain("Bacon");
});
});
But not if I change:
var meat = ""
driver.getPageSource().then(function(ss){
meat = ss;
});
because meat becomes empty and this fails: expect(meat).toContain(“Bacon”); with error: Expected ‘’ to contain ‘Bacon’.
I am even running it in interactive console mode with selenium and can parse the return as text using a then function to process the response after the promise. Why does this work in interactive selenium driver land and not my protractor js test?:
var meat = "";
driver.findElement(By.tagName("body")).getText().then(function(stuff){meat = stuff;});
> meat.indexOf('Bacon')
89
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Closing, since this bacon is crispy and done.
You could do that all within the promise callback, like so: