Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Parsing getText() return in JavaScript #858

@mishawagon

Description

@mishawagon

Dear 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions