首页 > 解决方案 > 在 Appium 和 Selenium 库的情况下,使用方法“捕获页面屏幕截图”的 Robot Framework 自动日志生成问题

问题描述

对于我的应用程序,我必须在 Web 应用程序上创建数据并在移动应用程序中对其进行验证,因此我的代码同时支持 Appium 和 Selenium 方法。在单个测试套件文件中,我同时调用了 selenium 和 Appium 方法,并且一切都运行成功。

但是,每当任何测试用例由于任何原因失败时,机器人框架自动日志文件都无法理解应该使用哪种方法来捕获页面截图 [Selenium OR Appium]?它会引发以下警告,并且不会捕获任何屏幕截图。

Keyword 'Capture Page Screenshot' could not be run on failure: Multiple keywords with name 'Capture Page Screenshot' found. Give the full name of the keyword you want to use:
    AppiumLibrary.Capture Page Screenshot
    SeleniumLibrary.Capture Page Screenshot

在测试套件文件中,我们可以定义Appium.Capture Page ScreenshotSelenium.Capture Page Screenshot但对于自动日志创建,我们如何解决这个问题?

标签: seleniumselenium-webdriverappiumrobotframework

解决方案


SeleniumLibrary 可以使用几个可选参数导入

timeout=5.0,
implicit_wait=0.0,
run_on_failure=Capture Page Screenshot,
screenshot_root_directory=None,
plugins=None,
event_firing_webdriver=None 
timeout: Default value for timeouts used with Wait ... keywords.

implicit_wait: Default value for implicit wait used when locating elements.

run_on_failure: Default action for the run-on-failure functionality.

screenshot_root_directory: Path to folder where possible screenshots are created or 
EMBED. See Set Screenshot Directory keyword for further details about EMBED. If not 
given, the directory where the log file is written is used.

plugins: Allows extending the SeleniumLibrary with external Python classes.

event_firing_webdriver: Class for wrapping Selenium with EventFiringWebDriver

run_on_failureArgument 应该可以解决 Selenium Screenshots 的问题

Appium 库有一个类似的参数

像这样导入库:

Library SeleniumLibrary  run_on_failure=SeleniumLibrary.Capture Page Screenshot
Library AppiumLibrary  run_on_failure=AppiumLibrary.Capture Page Screenshot

如果这不能解决问题,请尝试使用指定的 Test Teardowns


推荐阅读