在QAF中获取webelement文本

Get webelement text in QAF

我想在 QAF 的网页中获取特定网络元素的文本。对于硒,我们使用

element(by.id('id')).getAttribute('value');

如何在 QAF 中编写上述代码?

您可以使用与普通硒相同的方式,例如:

driver.findElement(By.id("id")).getAttribute('value');

除此之外,qaf 有多种实现方式。 假设您的定位器是 id=id,要创建元素对象,您可以使用以下方式之一:

new QAFExtendedWebElement(loc)
//or
driver.findElement(loc)

简写:

import static com.qmetry.qaf.automation.ui.webdriver.ElementFactory.$;


$(loc)

在代码中获取价值

   String val = $(loc).getAttribute("value");

代码中的assert/verify/wait值

    $(loc).verifyValue(expectedValue);
    $(loc).assertValue(expectedValue);
    $(loc).waitForValue(expectedValue);

使用来自 qaf-support 的内置 steps

    import static com.qmetry.qaf.automation.step.CommonStep.*;

    verifyValue(loc, value);
    assertValue(loc, value);
    waitForValue(loc, value);

Steps 到 assert/verify/wait BDD

中的值
    verify 'loc' value is 'expectedValue'
    assert 'loc' value is 'expectedValue'
    wait until 'loc' value is 'expectedValue'