【发布时间】:2018-05-13 20:41:02
【问题描述】:
我正在开发一个 selneium-appium-java 移动网络自动化框架。我有一个黄瓜测试,它使用正则表达式来接受一些文本并将其作为参数进一步传递,例如:
@Given("^user checks text \"([^\"]*)\" in footer$")
public void checkFooter(String footerText) {
footerComponent.checkNote(footerText);
}
这是当前在 FooterComponent 类中查找节点基本文本的设置方式
private final String FOOTER = "//div[contains(@class, 'footer')]";
public void checkNote(String expectedText) {
By note = By.xpath(FOOTER + "//div[@class='footer-footnote']");
String actualText = getDriver().findElement(footerText).getText();
assertEquals(actualText, expectedText, "Unexpected footer note");
}
我需要验证预期结果的 DOM 示例:
<div class='footer'>
text1
<span class="copysymbol"></span>
text2
<span class="dot"></span>
text3
<span class="dot"></span>
text4
<span class="dot"></span>
</div>
我尝试使用此处的模式,但没有成功: https://alvinalexander.com/blog/post/java/how-extract-html-tag-string-regex-pattern-matcher-group
所以基本上我需要插入一些文本来检查标签是否存在(代表我需要检查的特殊字符)以及它们之间的文本在黄瓜行中,然后让 java 方法检查实际代码通过使用 Xpath 找到它。有没有办法通过黄瓜使用正则表达式来完成?
【问题讨论】:
-
我认为使用 xPath 检查 HTML 比使用正则表达式要好得多。所以也许你可以在这里继续使用 xPath。
标签: java regex selenium-webdriver automation appium