【发布时间】:2018-12-20 12:12:18
【问题描述】:
在我们的项目中,我们使用黄瓜运行了多个硒测试,这些测试正在测试特定组件。这些组件之一是两个标识符,我们称之为国家标识符和站点标识符。 这些具有以下 HTML:
<div class="identifiers">
<div class="country-identifier">
<span class="ident-label">
Germany
</span>
</div>
<div class="site-identifier">
<span class="ident-label">
Gaming
</span>
</div>
</div>
现在我们的测试有两个模型,每个标识符一个:
@PageObject(css = "div.country-identifier")
@Named("CountryIdentifier")
@ScenarioScoped
public class CountryIdentifier {
@Inject
@CurrentScope
private WebElement scope;
@FindBy(className = "ident-label")
@CacheLookup
private WebElement label;
}
还有:
@PageObject(css = "div.site-identifier")
@Named("SiteIdentifier")
@ScenarioScoped
public class SiteIdentifier {
@Inject
@CurrentScope
private WebElement scope;
@FindBy(className = "ident-label")
@CacheLookup
private WebElement label;
}
现在的问题是,当我想访问站点标识符的标签时,WebElement 标签的值是 Germany 而不是 Gaming。这是因为获取值的 css 选择器显然只应用了类名 ident-label 而没有考虑容器类。我希望生成的用于查找标签的选择器会将为页面对象定义的 css 与 @FindBy 注释中的选择器结合起来。
有没有办法告诉 Web 驱动程序仅在 @PageObject 注释的 css 选择器中指定的容器范围内按类名查找元素?还是我需要 FindBy 注释中的完整 css 选择器,例如:
@FindBy(css = "div.site-identifier .ident-label")
还有
@FindBy(css = "div.country-identifier .ident-label")
【问题讨论】:
-
label of the site identifier不是having the value "Germany"但绝对是"Gaming"
标签: selenium selenium-webdriver css-selectors cucumber pageobjects