Question

A website displays the following text I need to assert:

Living Place "123" hasn't been found

I have a piece of ghurkin/cucumber on a webpage I need to assert.assertTrue using Selenum Webdriver Java:

The text "Living Place "123" hasn't been found" is present on the page

The java Code I've written for this, is as follows:

    @Then("^The Text \"([^\"]*)\" isnt present on the page$")   
    public void not_present(String text) throws Throwable {

    waitForTextInElementVisible(By.id("main-content"), text);
    Assert.assertTrue(driver.findElement(By.id("main-content")).getText().contains(text));
}

The problem is, the Gherkin script can't handle the String this way, as it contains a double quote. Is there a way to assert the exact string as given above?

Was it helpful?

Solution 3

Apparently, instead of using \"([^\"]*)\",

I had to use \"(.*)\"

this will make the gherkin script work:

And The text "Living Place "123" hasn't been found" is present on the page

OTHER TIPS

I am not sure if I get your problem fully.

But you can pass the string as "Living Place \"123\" hasn't been found". [Note \ before " inside string]

You can call like follows. not_present("Living Place \"123\" hasn't been found");

try this one @Then("^The Text \"([^\"]*)\"\d+\"([^\"]*)\" isnt present on the page$"). This step mapping will be mapped to string in feature file Then The Text "Living Place "123" hasn't been found" isnt present on the page. This substitutes the text before digits \"([^\"]*)\" i.e. 'Living Place ', this searches more then one digit symbol in quotation marks \"\d+\" i.e 123, and again part to match text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top