-2

I would like to verify that date which appears in the string matches todays date.

For examples: 1. Navigate to Page 2. Get displayed string text "Data Current as of 2017-10-17" 3. Assert to today's date for pass/fail

Gamcusa
  • 1
  • 3

1 Answers1

0

`WebElement dateText = driver.findElement(By.xpath("//div[contains(.,'Data Current as of')]"));

    String fullDateString = dateText.getText();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    String patternString = "(\\d+-\\d+-\\d+)";//use of Reg Ex

    Pattern pattern = Pattern.compile(patternString);

    Matcher matcher = pattern.matcher(dateText.getText());

    Date repodate = new Date();

    while (matcher.find()) {
        repodate = df.parse(matcher.group());
    }

    Date currDate = df.parse(df.format(new Date()));

    if (currDate == repodate) ///verifing
        ;
    {
        System.out.println(currDate);
        System.out.println(repodate);
    }

    Assert.assertEquals(repodate, currDate);//asserting`
Gamcusa
  • 1
  • 3