0

Is there a way to select the validation pop-up messages generated by the browser when a user inputs an incorrect format, such as an invalid email address?.
I am writing a test case to verify whether the browser's validation message disappears once the user corrects the email format to the correct one.

// URL to test : https://phptravels.net/login

    @Test(priority = 27)
    public void verifyErrorMessageDisappearsOnInputChange() throws InterruptedException {

        loginPage.enterEmail("wrongphptravelscom");
        loginPage.enterPassword("wrongpass");
        loginPage.clickLogin();
            
        WebElement emailInput = driver.findElement(By.id("email"));
        JavascriptExecutor js = (JavascriptExecutor) driver; 
        String validationMessage = (String) js.executeScript("return arguments[0].validationMessage;", emailInput);    

        Assert.assertTrue(validationMessage.length() > 0);      
        loginPage.enterEmail(validEmail);
        loginPage.clickLogin();        
        Assert.assertTrue(loginPage.getErrorMessage().isEmpty() || loginPage.getErrorMessage().length() == 0);
    }
1
  • You could verify that the browser lands on the expected URL after the email address is corrected. Commented Oct 8 at 3:32

1 Answer 1

0
  @Test(priority = 27)
    public void verifyErrorMessageDisappearsOnInputChange() throws InterruptedException {
        loginPage.enterEmail("wrongphptravelscom");
        loginPage.enterPassword("wrongpass");
        loginPage.clickLogin();
        
        WebElement emailInput = driver.findElement(By.id("email"));
        
        JavascriptExecutor js = (JavascriptExecutor) driver;
        String message = (String) js.executeScript("return arguments[0].validationMessage;", emailInput);
        
        System.out.println(message);
        emailInput.clear();

       loginPage.enterEmail(validEmail);
       
       String messageAfterFix = (String) js.executeScript("return arguments[0].validationMessage;", emailInput);
       System.out.println("messageAfterFix : "+ messageAfterFix);
       Assert.assertTrue(messageAfterFix.isEmpty(), "Validation message should disappear for valid email");
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.