0

I have a table with unknown values (which I need to log in later) and I would like to save one of it with class currentWeek to a variable. HTML is as following:

<tr _ngcontent-c21="" class="currentWeek">
    <th _ngcontent-c21="" class="text-center">Value1Foo</th>
    (...)
</tr>

In proctracor I created in Helper.ts:

static getfooOfTheWeek() {
    let child = element(by.css('.currentWeek')).$('.text-center');

    describe('Get foo', function () {
        it('get foo', function () {
            browser.driver.get('tablepage');
            browser.sleep(3000);
            return ((child).getText()).toString();
        })
    })
}

and in file maintest.ts:

describe('Get FOO', function () {
    var FOO=Helper.getfooOfTheWeek();
    browser.sleep(2000);
    //use the value set in Helper.getfooOfTheWeek();
    NegativeTest.SomeTest(FOO);
});

but it fails ususally with - Failed: each key must be a number of string; got undefined - therefore I think the FOO is save as an Object, not as string.

I thought also using JSON (to use JSON.parse()), but developers can't gives the values to the table from JSON

Any path what I can try?

Michal
  • 443
  • 1
  • 10
  • 25

1 Answers1

0

Got it - found this issue about saving as string instead of object: Protractor: element.getText() returns an object and not String where I need to resolve the promise

and instead of passing it as variable with var FOO=Helper.getfooOfTheWeek(); I saved it as browser.params.Foo

static getfooOfTheWeek() {
    let child = element(by.css('.currentWeek')).$('.text-center');

    browser.driver.get('tablepage');
    browser.sleep(3000);
    child.getText().then(function(text) {
        browser.params.Foo=text;
    });
}

and I can run NegativeTest.SomeTest(); where the variable is passed in SomeTest() as browser.params.Foo (instead of writting there FOO)

Michal
  • 443
  • 1
  • 10
  • 25