How to avoid random Pages, Screen, Modal in Java?

When i run my code everytime pass by login, after fill every field and click on the button, my code validates if the word: “Descubra” of page “Descubra” is displyed:

//Esperando a página: “Descubra Carregar”
WebDriverWait aguardarCarregarPaginaDescubra = new WebDriverWait(driver, 20);

//Pegando o texto do Descubra
String textoDescubra = driver.findElementById(“”).getAttribute(“content-desc”);

//Comparando se o Texto Exibido é o Descubra para validar se o login foi realizado com sucesso
Assert.assertEquals(“Descubra”, textoDescubra);

This page is what my code validates

although, sometimes is displayed a random page,random screen, random modal, and always the validation returns with error, how i can avoid this kind of stuff ?

This is the random page, random modal that is displayed sometimes

Here are the three things I can see you doing here:

  1. Ask developers not to include modal screen in debug app
  2. Write your code with a decision tree (if/elsif/else, or switch) that will allow you to handle the modal in code
  3. Write your code with a Screen Factory, and the instead of writing the tests to instantiate a particular screen, you just ask the Screen Factory to return the current screen and then have your code handle that particular screen.

Option 3 is what we do in our code. No idea what language you use so here’s a generic definition:

1 Like

Thanks, i will try these option