/
githubmirror
/
servo
Обзор
Документация
Войти
/
githubmirror
/
servo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
etc/ci/scenario/common_function_for_mossel.py
86 строк
3 KB
Asset Malik
ci: Fix etc/ci/scenario Python types (#45204)
01 июн 2026, 20:46
Не верифицирован
01 июн 2026, 20:46
6400c3d
Код
Авторство
О чём код?
#!/usr/bin/env python3 # Copyright 2025 The Servo Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution. # # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your # option. This file may not be copied, modified, or distributed # except according to those terms. from selenium.common import NoSuchElementException from selenium.webdriver.common.by import By from selenium import webdriver from time import sleep def load_mossel(driver: webdriver.Remote) -> None: PAGE_URL = "https://m.huaweimossel.com" driver.set_page_load_timeout(30) while True: try: driver.get(PAGE_URL) try: driver.find_element(By.CSS_SELECTOR, ".uni-async-error") print("\033[31mMossel timeout JS triggered, reloading...\033[0m") except NoSuchElementException: break except Exception as e: print(f"\033[31mPage load failed: {e}\033[0m") print("Retrying...") continue print("\033[32mPage loaded.\033[0m") # Click to close the pop-up # Note that the pop-up may not exist, either because we did this in the past # which sets localstorage, or the website does not have seasonal promotions/recommendations. # ASSUMPTION: driver is already created, and implicit wait is set properly. def close_popup(driver: webdriver.Remote) -> None: popup_css_selector = ( "#app > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view " "> uni-view:nth-child(5) " "> uni-view.m-popup.m-popup_transition.m-mask_show.m-mask_fade.m-popup_push.m-fixed_mid " "> uni-view > uni-view > uni-button:nth-child(1)" ) print("Waiting for popup to appear ...") try: birthday_element = driver.find_element(By.CSS_SELECTOR, popup_css_selector) birthday_element.click() print("Closed the popup") sleep(1) except NoSuchElementException: print(f"Failed to find pop_up element with selector `{popup_css_selector}`. Skip it.") def click_category(driver: webdriver.Remote) -> None: print("Clicking 'Categories' element.") category_css_selector = "div.uni-tabbar__item:nth-child(3)" try: category_element = driver.find_element(By.CSS_SELECTOR, category_css_selector) except NoSuchElementException: raise NoSuchElementException("Category element not found. Test failed.") category_element.click() def identify_element_in_category(driver: webdriver.Remote) -> None: driver.implicitly_wait(30) target_css_selector = "#goodsGroup" while True: try: print("Finding components ...") driver.find_element(By.CSS_SELECTOR, target_css_selector) break except NoSuchElementException: # We hit the timeout JS, reload and try again. print("\033[31mMossel timeout JS triggered, reloading...\033[0m") try: driver.refresh() except Exception as e: print(f"\033[31mPage refresh failed: {e}\033[0m") print("Retrying...") continue print("\033[32mComponents found!\033[0m")