jeudi 6 octobre 2016

Convert JSON to Pattern on Selenium WebDriver

I want to use JSON to compare String. I have website in different language so i take string from JSON file.
String could be:

Gender: Male 

or

Gender: Female

In Selenium IDE i write:

try {
  assertTrue(Pattern.compile("Gender: *(Male|Female)").matcher(driver.findElement(By.xpath("//span[3]")).getText()).find());
} catch (Error e) {
  verificationErrors.append(e.toString());
}

and now I want to convert this to Java using JSON and SeleniumWebDriver

protected static void feedbacksCheck(WebDriver driver, JSONObject pageLanguage) throws JSONException {
    assertEquals(true ,Pattern.compile(pageLanguage.get("GENDER")+": " +"*(" +pageLanguage.get("MALE") +"|" +pageLanguage.get("FEMALE")+")").matcher(driver.findElement(By.xpath("//div[2]/div/span")).getText()).find());        
}

I don't know if this work ok because on compare result I could see true or false. How to change this code to see on compare result all string from website?

Aucun commentaire:

Enregistrer un commentaire