thmo 无法解析为变量

问题描述 投票:0回答:1

我目前正在使用 Page 对象模型和 cucumber 通过 Java 练习 selenium
对于我的黄瓜文件,我用过这个

And I select the Month as "'January'" and date as "'22'" and the year as "2025"

我在

xpath
页面文件中使用这个
pom
作为

By date=By.xpath("//*[contains(@arialabel,"+thmo+")]/div/p[text()="+da+"]");
By btn_traveller_type=By.xpath("//*[text()='"+ty+"']");
By btn_class=By.xpath("//div[text()='"+cl+"']");

这是我做的方法

public void select_date(String mo, String da, String ye) {
    String cleanedWord = mo.replace("'", "");
    String thmo = cleanedWord.substring(0, 3);
    String monthYear= cleanedWord+" "+ye;
    while(true) 
    {
        wait.until(ExpectedConditions.visibilityOfElementLocated(css_calender));
        String displayedMonthYear =driver.findElement(xpath_calender).getText();
        //String displayedMonthYear = driver.findElement(By.cssSelector(".DayPicker-Caption div")).getText();
        if (displayedMonthYear.equals(monthYear)) 
        {
            wait.until(ExpectedConditions.elementToBeClickable(date)).click();
            break;
        } else 
        {
            driver.findElement(btn_nextmonth).click();
            //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@aria-label='Next Month']"))).click();
        }
    }

我收到此错误

thmo cannot be resolved to a variable  
da cannot be resolved to a variable  
ty cannot be resolved to a variable  
cl cannot be resolved to a variable  

它应该从黄瓜特征文件中选择变量

thmo,da,ty,cl
并在
xpaths
中使用它。

java selenium-webdriver cucumber-java pageobjects
1个回答
0
投票

可能您在映射小黄瓜线的方法之前缺少 Cucumber 注释。

可以在方法前添加这个注解,如下

@When("And I select the Month as {String} and date as {String} and the year as {String}")
public void select_date(String mo, String da, String ye)

这样Gherkin语言中的第一个、第二个和第三个值分别映射到方法的mo、da和ye变量

© www.soinside.com 2019 - 2024. All rights reserved.