samedi 23 septembre 2017

How to track that value of an element finished changing in Selenium WebDriver?

I'm testing online Game here http://ift.tt/1z5dtrk

I want to create a test to verify if credits value is the same after page refresh

public class VerifyGameAfterRefresh extends BaseTest{

@Test(invocationCount = 1)
public void testAfterRefresh(){
    GamePage gamePage = new GamePage(driver);
    gamePage.isLoaded();
    int times = getRandInt(2,5);
    //change bet value
    gamePage.clickSpinUpButton(times);
    //click on spin button
    gamePage.clickSpinButton(times);
    int creditsValue = gamePage.getCreditsValue();
    gamePage.pageRefresh();
    int creditsValueAfterRefresh = gamePage.getCreditsValue();

    Assert.assertEquals(creditsValue,creditsValueAfterRefresh,"Credit after refresh are not the same");
    Assert.assertTrue(gamePage.getBetValue() == 1, "Bet value was not set to default");
  }
}

Method to get creditsValue :

    public int getCreditsValue(){
    //wait.until(ExpectedConditions.
    int value = Integer.parseInt(creditsValue.getText());
    return value;
}

Everything works perfect until the case when during last click on spin we win. In this case <span id="credits">value</span> value is changing dynamically, but my method does not wait till the end of the changing and grab the value at the beginning that after leads to test fail.

May I use some functionality of wait.until(ExpectedConditions. just to wait for my value to be stable?

Or what would you recommend?

Aucun commentaire:

Enregistrer un commentaire