Articles → SELENIUM → Test Validations In Web Application Using Selenium

Test Validations In Web Application Using Selenium






Steps




  1. Go to http://gyansangrah.com/ContactUs.aspx
  2. You will see the following web form.
  3. Picture showing the contact us page of gyansangrah.com
    Click to Enlarge

  4. Click on ‘Submit’ button.
  5. Alert message should be appearing with this text – ‘Invalid email’.

Code


package com.FirstSeleniumProject;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class MyClass {

	public static void main(String[] args) {
		WebDriver driver;
		String service = "IEDriverServer path";
		System.setProperty("webdriver.ie.driver", service);
		driver = new InternetExplorerDriver();
		driver.get("http://gyansangrah.com/ContactUs.aspx");

		driver.findElement(By.name("ctl00$cphGyanSangrah$btnSubmit")).click();
		//driver.switchTo().alert().accept();
		Alert alert = driver.switchTo().alert();

		String alertMessage = alert.getText();
		alert.accept();

		WebElement emailId = driver.findElement(By.name("ctl00$cphGyanSangrah$txtEmailID"));

		String textInsideInputBox = emailId.getAttribute("value");
		// Check whether input field is blank
		if (textInsideInputBox.trim().equalsIgnoreCase("Your Email ID") && alertMessage.trim().equalsIgnoreCase("Invalid email")) {
			System.out.println("Email Validation is fine");
		}

	}
}



Output


Picture showing the output of Test validations in web application using Selenium
Click to Enlarge

Picture showing the output of Test validations in web application using Selenium
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, April 17, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250