באנדרואיד, אוטומציה ל-Chrome דומה:
יש הבדל בפונקציה שמקבלת את הדרייבר של Android Chrome:
def test_android_chrome_core_actions(android_chrome, by):
"""Teach common Appium actions for a website opened in Android Chrome."""
# Open the demo website through the Android Emulator localhost bridge.
android_chrome.get(settings.android_base_url)
# Start an Allure step for the first mobile web tap.
with allure_step("Tap a web button and wait for status text"):
# Android Chrome web tests can reuse CSS selectors from Selenium tests.
clickable(android_chrome, (by.CSS_SELECTOR, "[data-testid='hero-cta']")).click()
# Wait until the status text proves the tap worked.
text_present(android_chrome, (by.CSS_SELECTOR, "[data-testid='practice-status']"), "Practice started")
לעומת הדרייבר של Chrome במחשב
def test_desktop_chrome_core_actions(desktop_chrome, by):
"""Teach the most common Selenium actions for a desktop Chrome website."""
# Open the demo website in Desktop Chrome.
desktop_chrome.get(settings.base_url)
# Attach the opened URL to the Allure report.
attach_text("Opened URL", desktop_chrome.current_url)
# Start an Allure step for the first click flow.
with allure_step("Click a button and wait for status text"):
# Desktop web tests usually use stable CSS selectors such as data-testid.
clickable(desktop_chrome, (by.CSS_SELECTOR, "[data-testid='hero-cta']")).click()
# Wait until the status text proves the click worked.
text_present(desktop_chrome, (by.CSS_SELECTOR, "[data-testid='practice-status']"), "Practice started")
בנוסף יש הבדל ב-tags
אם באוטומציה של Chrome במחשב זה היה:
# Mark this file as Desktop Chrome, Selenium, and smoke-test coverage.
pytestmark = [pytest.mark.desktop_chrome, pytest.mark.selenium, pytest.mark.smoke]
אז עבור אוטומציה של Android זה:
# Mark this file as Android Chrome, Appium, Android, and smoke coverage.
pytestmark = [pytest.mark.android_chrome, pytest.mark.appium, pytest.mark.android, pytest.mark.smoke]
# Enable modern type-hint behavior for this file.
from __future__ import annotations
# Import Allure decorators for report grouping.
import allure
# Import pytest to mark this test with environment labels.
import pytest
# Import Select for working with real HTML <select> dropdowns.
from selenium.webdriver.support.select import Select
# Import shared URLs and environment settings.
from wulfauto.config.settings import settings
# Import the Allure step helper.
from wulfauto.core.allure_utils import allure_step
# Import explicit wait helpers used before actions.
from wulfauto.core.waits import clickable, text_present, visible
# Mark this file as Android Chrome, Appium, Android, and smoke coverage.
pytestmark = [pytest.mark.android_chrome, pytest.mark.appium, pytest.mark.android, pytest.mark.smoke]
יש גם URL שונה על בסיס ההגדרות לאנדרואיד
# Open the demo website through the Android Emulator localhost bridge.
android_chrome.get(settings.android_base_url)
חיפוש אלמנטים מתרחש באותו אופן כמו במחשב
# Start an Allure step for the first mobile web tap.
with allure_step("Tap a web button and wait for status text"):
# Android Chrome web tests can reuse CSS selectors from Selenium tests.
clickable(android_chrome, (by.CSS_SELECTOR, "[data-testid='hero-cta']")).click()
# Wait until the status text proves the tap worked.
text_present(android_chrome, (by.CSS_SELECTOR, "[data-testid='practice-status']"), "Practice started")
בנוסף, יש פקודות מותאמות לסמארטפון – כמו להסתיר מקלדת
# Mobile keyboards often cover controls, so hide it before the next tap.
android_chrome.hide_keyboard()
אבל כל השאר זהה כמו ב-Chrome של המחשב.