我目前正在使用 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
中使用它。
可能您在映射小黄瓜线的方法之前缺少 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变量