-1

I am implementing as automation script and following BDD frame work with selenium webdriver.

Acceptance Criteria:

Scenario: Members name

    Given that the web page is displayed
    When the user clicks anywhere on the member row
    Then member First Name, Middle Initial, Last Name will be  displayed
    And Member First Name, Middle Initial, Last name display in Camel case

Would you pleas let me know how to validate the Camel case for displayed information in web page? Like "Jhon D Hamton".

Eugene S
  • 6,709
  • 8
  • 57
  • 91
Farhad
  • 1
  • 2

3 Answers3

0

Well, assuming you can grab your string, I'd split it then check that the first letter is uppercase:

boolean isCamelCase(String s) {
    String[] split_string = s.split(" ");
    for(int i=0;i<split_string.length;i++) {
        if(!Character.isUpperCase(split_string[i].charAt(0))){
            return false;
        }
    }
    return true;
}
James
  • 2,843
  • 1
  • 14
  • 24
  • Thank you so much for the solution. Would you please explain that how it validates the first letter of First name , Middle initial, Last name is Capital. As I want to validate only the first letter is capital letter. – Farhad Aug 01 '16 at 01:48
  • Oops! Had a minor syntax error in there (fixed now). What it does is split the string into its words and puts those words in an array, then cycles through the array and checks if the first letter in each word is uppercase. – James Aug 01 '16 at 01:52
  • This my code: String Name = driver.findElement(By.xpath("xpath_expression").getText(); System.out.println(Name); Jhon D Hampton Would you please provide code that validates that First name, Middle initial and Last name are capital? – Farhad Aug 01 '16 at 02:05
  • I've changed it to be a function that does what you're requesting - not sure what else you're looking for. – James Aug 01 '16 at 02:08
  • Thank you so much James ! appreciate your help – Farhad Aug 01 '16 at 02:29
0

If you know how, or are able to get the entire name as a string, you can use the following Regex to assert that it is camel case:

[A-Z]([A-Z0-9]*[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]*

This matches strings that start with an uppercase letter, contain only letters and numbers, and contain at least one lowercase letter and at least one other uppercase letter.

For Java, you want to call the String class's matches() method, which returns true or false:

boolean doesItMatch = yourString.matches('theRegexAbove');
Tyler Russell
  • 299
  • 2
  • 10
0

By using WordUtils in the Apache Commons lang library:

Specifically, the capitalizeFully(String str, char[] delimiters) method should do the job:

String blah = "LORD_OF_THE_RINGS";
assertEquals("LordOfTheRings", WordUtils.capitalizeFully(blah, new char[]{'_'}).replaceAll("_", ""));

Resource Link:

What is the simplest way to convert a Java string from all caps (words separated by underscores) to CamelCase (no word separators)?

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132