variablescodeceptjs

Grab text from span and then compare it using CodeceptJS


I have this in source on one page:

<span class="price-length price-length--4">666</span>

And I have this in source on another page

<span class="price-length price-length--7">777</span>

I want to grab that 666 value, store it somewhere, and compare to 777. How to do that using codeceptjs?

I tried I.grabValueFrom('some_xpath_to_value'), but I don't understand how to reuse it. How to see value that I.grabValueFrom function returns in codeceptjs?


Solution

  • You can use a generator function to return values via 'yield' from functions like so:

    Scenario('Yield', function* (I) {
      let value = yield I.grabValueFrom(some_xpath_to_value);
    
    
      let assert = require('assert');
      assert.equal(value, '777');
    });