SeleniumBase 和 Appium 的集成,以利用 SeleniumBase API 与移动设备

问题描述 投票:0回答:1

我目前正在进行一个测试项目,需要执行网络和移动测试。对于网络自动化,我一直在使用 SeleniumBase,事实证明它非常有帮助。对于移动自动化,我使用 Appium。我的目标是集成这两个工具以利用 SeleniumBase 为移动设备提供的功能。

想知道是否可以在移动设备上使用 SeleniumBase 丰富的 api? 我确实启动了 appium 服务器并在 Pytest 固定装置中创建了驱动程序

import pytest
import logging
from . import appium_server
from . import appium_driver

# Configure logging
logging.basicConfig(level=logging.DEBUG)  # Set the desired logging level


@pytest.fixture(scope="session")
def run_appium_server():
    logging.getLogger("run_appium_server").debug("invoked appium server fixture")
    appium_server_instance = appium_server.start_appium_server()
    print(appium_server_instance)

    yield
    print("stopping appium server")
    appium_server.stop_appium_server(appium_server_instance)

    # driver.quit()


@pytest.fixture
def run_appium_driver(request, run_appium_server):

    print("function level appium driver")
    driver = appium_driver.start_appium_driver()
    print("Driver information:")
    print(driver)
    yield driver
    print("trying to quit driver, but commented")
    driver.quit()

我的测试用例文件继承了BaseTestCase,它又继承了BaseCase类

class TestDemo(BaseTestCase):

    @pytest.mark.usefixtures("run_appium_driver")  # Use the fixture to get the driver
    def test_hello_world(self):
        print("executing test helllo world")
        print(run_appium_driver)
        
  self.base_test_case.find_element(By.ID,"com.company:id/get_started_button")


# if __name__ == "__main__":
#     TestDemo.main()

BaseTestCase.main(__name__, __file__)

此代码不起作用,因为 selenium 无法识别移动应用程序中的元素。 集成的目的是将 SeleniumBase api 与 appium 结合使用,以支持 SeleniumBase api,报告内容。

selenium-webdriver appium appium-android python-appium seleniumbase
1个回答
0
投票

有几种方法可以解决这个问题。有内置的 SeleniumBase 移动模式,可通过

--mobile
作为
pytest
命令行选项激活。您还可以通过其他参数进行自定义:

--agent=STRING  (Modify the web browser User-Agent string.)
--mobile  (Use the mobile device emulator while running tests.)
--metrics=STRING  (Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio".)

但是如果您需要将 Appium 与它一起使用,请参阅 SeleniumBase 语法格式 9 - 通过 BaseCase 覆盖驱动程序,或参阅 SeleniumBase 语法格式 10 - 通过“sb”固定装置覆盖驱动程序

您基本上会重写

get_new_driver()
,以便当 SeleniumBase 启动时,它会启动 Appium 驱动程序而不是用于测试的常规驱动程序。如果您使用 pytest 装置,您可能需要格式 10。

假设常规 Webdriver API 与 Appium API 兼容,您将能够在 Appium 中使用与 Webdriver 已使用的相同方法。

© www.soinside.com 2019 - 2024. All rights reserved.