how to test validations for "FIRSTNAME" textfield. Below are the details and code.
URL: http://www.vrlbus.in/vrl2013/register_customer.aspx
Special chars: #!#!#$@#!$@!$@#$%#%^#$^^&%&$%* (Not valid).
Alphabetic chars: acbcdefghijklmnopqrstuvwxyzabcdef (Valid).
Code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Validations {
public static WebDriver d;
public static void main(String []args)throws Exception{
d = new FirefoxDriver();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
d.get("http://www.vrlbus.in/vrl2013/register_customer.aspx");
d.findElement(By.id("FIRSTNAME")).sendKeys("#!#!#$@#!$@!$@#$%#%^#$^^&%&$%*");
d.findElement(By.id("Button1")).click();
String alertMessage = d.switchTo().alert().getText();
System.out.println(alertMessage);
if (alertMessage.equals("First name Should not contain Special Characters")){
System.out.println("Error displayed: First name Should not contain Special Characters");
d.switchTo().alert().dismiss();
} else{
System.out.println("Accepted");
}
d.findElement(By.id("FIRSTNAME")).sendKeys("acbcdefghijklmnopqrstuvwxyzabcdef");
d.findElement(By.id("Button1")).click();
if (alertMessage.equals("First name Should not contain Special Characters")){
System.out.println("Error displayed: First name Should not contain Special Characters");
d.switchTo().alert().dismiss();
} else{
System.out.println("Accepted");
}
d.quit();
}
}