首页 > 解决方案 > 运行 Cucumber 测试时会抛出错误并使用以下代码段实现未定义的实现

问题描述

在运行 Cucumber/javascript/selenium 网络驱动程序测试时,我得到了一个Undefined. Implement with the following snippet: this.Then(/^I should display "([^"]*)" under the search area$/, function (arg1, callback){ callback(null, 'pending');..... 在搜索区域输入文字时,系统会在搜索输入框下方显示结果列表。在显示的结果中,我正在寻找带有文本“建筑设计师”的元素。知道为什么这是 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

// 搜索步骤.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);        
        });     
    })

在此处输入图像描述

标签: javascriptselenium-webdrivercucumber

解决方案


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

最后你有一个 & 而不是 $


推荐阅读