Search code examples
javascriptinternleadfoot

Events after clickMouseButton


In one of my tests I have the mouse moved to a specific location and then clickMouseButton() is called. This action is to change the data that is displayed (paging the data.) However, after the click, when I try to get the text in a column of the table to verify that the data changed the data changes back to what was originally displayed and my test fails. My test code is:

return Remote
    .moveMouseTo(JE.Buttons.Scrolling(), 5, 100)
    .clickMouseButton()
    .end(Infinity)
    .sleep(500)
    .findByXpath('//*[@id="vwNJEAll_grid_header_tbody"]/tr[2]/td[2]/div')
    .getVisibleText()
    .then(function (result) {
        expect(result).not.to.equal(firstSeenJENumber);
    });

The code behind JE.Buttons.Scrolling() is:

return Remote
    .setFindTimeout(5000)
    .findByXpath('//*[@id="vwNJEAll_grid_table_container"]/div[2]/div');

It really seems to me like the locator in Leadfoot is binding to what is on the page when it first loads. Is this the case, and how should I go about getting what I need to happen? I have no other explanation for this, but hopefully you do.


Solution

  • moveMouseTo doesn’t accept a Promise as its first argument, so that moveMouseTo call is wrong and won’t do what you want. The JE.Buttons.Scrolling() call in your example code also occurs immediately (during command chain construction), it doesn’t occur only once moveMouseTo is actually performed.

    To retrieve and use an element with your abstraction function, pass the function to then and then use the element:

    return Remote
      .then(JE.Buttons.Scrolling)
      .then(function (element) {
        return Remote.moveMouseTo(element, 5, 100);
      })
      // …remainder of test…