Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
suju_26pro
Posts : 1
Join date : 2014-12-12

Need to perform validation testing for field Empty Need to perform validation testing for field

Tue Dec 16, 2014 4:38 pm
Hello ,

This is my code for webdriver where is assert for Alertbox , but i have a field where instead of alertbox validation text is showned when clicked on button,.This is code i get for asserting text validation
Code:
   assertEquals("Special Characters are not allowed.",
driver.findElement(By.cssSelector("span.field-validation-error >
span")).getText());

How to automate that scenario

Code:
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;


public class FirstName{
 
 public static void main(String[] args) throws Exception {
    String[] invalidChars = {"#", "!", "$", "@", "%", "^", "&"};
    String name = "acbcdefghijklmnopqrstuvwxyzab";
    FirefoxDriver d = new FirefoxDriver();
    d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    d.get("websiteurl gors here/Register");
    for (String invalid : invalidChars) {
        d.findElement(By.id("FirstName")).clear();
        d.findElement(By.id("FirstName")).sendKeys(name + invalid);
        d.findElement(By.id("CreateAccount")).click();
                String alertMessage = d.switchTo().alert().getText();
        System.out.println(invalid);
        if (alertMessage.equals("Special Characters are not allowed."))
        {
            System.out.println("Error displayed: First name Should not contain Special Characters");
            d.switchTo().alert().dismiss();
        } else {
            System.out.println("Accepted");
        }
    }
    
    
    d.quit();
 }

}
Back to top
Permissions in this forum:
You cannot reply to topics in this forum