soccerway
soccerway

Reputation: 11991

While running the Cucumber test throws error and undefined implement with the following snippet

While running the Cucumber/javascript/selenium web driver test, I am getting an Undefined. Implement with the following snippet: this.Then(/^I should display "([^"]*)" under the search area$/, function (arg1, callback){ callback(null, 'pending');..... While typing the text in the search area, system will display a list of results under the search input box. Out of the results displaying, I am looking for an element with text 'Building Designers'. Any idea why this is throwing as undefined ?

Feature: Test search 
   Scenario: List all the items based on input text provide in search
        When I typed the following "Building" text in input
        Then I should display "Building Designers" under the search area

// search-steps.js

this.When(/^I typed the following "([^"]*)" text in input$/, (text) =>{
      return helpers.loadPage('https://www.sometestsite.com')    
      .then(()=>{
          driver.findElement(By.id('search')).sendKeys(text);
      })
    })



this.Then(/^I should display "([^"]*)"under the search area&/, function (mytxt){
        return driver.wait(until.elementsLocated(By.cssSelector("div.SearchResults--result.button")), 50000).getText().then(el => {
        console.log("print text here:"+el);
        const displayTxt = el;  
        expect(displayTxt).to.be.eql(mytxt);        
        });     
    })

enter image description here

Upvotes: 0

Views: 1055

Answers (1)

Jsmith2800
Jsmith2800

Reputation: 1113

this.Then(/^I should display "([^"]*)"under the search area&/, function (mytxt){

You have an & instead of a $ at the end

Upvotes: 2

Related Questions