Selenium 我们能够在页面对象模型中打印对象和xpath吗
我正在使用testng+java+maven使用POM。为了报告的目的,我们可以在logs/extendreport中按objectname打印吗? 我正在使用Log4j和extentreports 示例:Mycommonfunction类包含为测试用例执行的所有操作:Selenium 我们能够在页面对象模型中打印对象和xpath吗,selenium,selenium-webdriver,ui-automation,Selenium,Selenium Webdriver,Ui Automation,我正在使用testng+java+maven使用POM。为了报告的目的,我们可以在logs/extendreport中按objectname打印吗? 我正在使用Log4j和extentreports 示例:Mycommonfunction类包含为测试用例执行的所有操作: public void click(By element) { WebElement webElement = getElement(element); try { Lo
public void click(By element) {
WebElement webElement = getElement(element);
try {
Log.info("Clicking on the webelement " + element);
webElement.click();
ExtentTestManager.getTest().info("clicking on the webelement - " + element);
}
catch (NoSuchElementException e) {
Log.error(e.getMessage());
ExtentTestManager.getTest().fail(e);
throw new TestException(String.format("The following element is not clickable: [%s]", element));
}
}
在我的pageobject类中,我将xpath声明为:
By clearFormButton = By.xpath("//*[@id='createPopulation:j_idt198']");
and in my test step:
commonfunction.click(clearFormButton);
Actual output : Clicking on the webelement By.xpath:
//*[@id='createPopulation:j_idt198']
Expected output : Clicking on the webelement clearFormButton - By.xpath:
//*[@id='createPopulation:j_idt198']
e.extraInfo.get(“***元素信息”)
将为您提供定位器及其值
log.debug(e.extraInfo.get(“***元素信息”))
您可以使用获取类实例的字段值,如下所示:
java.lang.reflect.Field field = element.getClass().getDeclaredField("foundBy");
field.setAccessible(true);
String foundBy = field.get(element).toString();
您对的实现有点奇怪,顺便说一句,我的设想是您的测试不应该有任何Selenium内部构件,所以不要使用
commonfunction代码>在测试步骤中,您应该有类似于CreatePopulationPage=myCurrentPage的内容。单击createpopulationbutton()代码>按类型变量名“element”将在代码中打印在哪里?问题要求在log.info或extent report log中按变量名打印以获取信息,但这里的答案仅适用于异常发生时的情况??请,请,当您仅通过ID定位元素时,请不要使用XPath。使用By.ID()
取而代之。你真的想在成功点击的海洋中寻找不起作用的点击吗?不要记录单击,而是学习如何在堆栈跟踪失败并抛出错误时读取堆栈跟踪。堆栈跟踪将准确地告诉您脚本在哪一行失败,以及定位器信息。
java.lang.reflect.Field field = element.getClass().getDeclaredField("foundBy");
field.setAccessible(true);
String foundBy = field.get(element).toString();