首页 > 其他分享 >driver refactor

driver refactor

时间:2023-08-23 13:33:34浏览次数:20  
标签:return get self driver refactor window def

1. 

class SentryUIChromeDriver(BaseDriver):
def __init__(self, **browser_args):
from selenium.webdriver.chrome.service import Service
try:
self.driver = Chrome(**browser_args)
except WebDriverException:
#self.driver_path = install_matching_chrome_driver()
#self.driver = Chrome(service=Service(self.driver_path), **browser_args)
self.driver = Chrome(service=Service(ChromeDriverManager().install()),**browser_args)
super().__init__(self.driver)
atexit.register(self.kill_service)


2.
from Element.Element import Element
from Utilitys.WaitUtils import WaitUtils


class BaseDriver(Element):

def __init__(self, driver):
super().__init__(driver)

def get_driver(self):
return self

def find_element(self, by, value):
try:
try:
return self.driver.find_element(by, value)
except Exception:
self._refresh()
WaitUtils.wait_for_element_present(self.driver, by, value)
return self.driver.find_element(by, value)
except Exception:
raise Exception("Cannot find element by [%s]:[%s] under:\n %s \n" % (by, value, self))

def find_elements(self, by, value, number=1):
try:
if len(self.__find_elements(by, value)) >= number:
return self.__find_elements(by, value)
else:
raise Exception
except Exception:
self._refresh()
WaitUtils.wait_for_elements_number_right(self._appium_context(), by, value, number)
return self.__find_elements(by, value)

def __find_elements(self, by, value):
try:
try:
return self._appium_context().find_elements(by, value)
except Exception:
self._refresh()
WaitUtils.wait_for_element_present(self._appium_context(), by, value)
return self._appium_context().find_elements(by, value)
except Exception:
raise Exception("Cannot find element by [%s] under: \n %s \n" % (value, self))

def before_startup(self, method):
self.driver.start_client = method

def after_shutdown(self, method):
self.driver.stop_client = method

def start_session(self, desired_capabilities):
self.driver.start_session(desired_capabilities)

def set_page_load_timeout(self, timeout):
self.driver.set_page_load_timeout(timeout / 1000.0)

def set_script_timeout(self, time_to_wait):
self.driver.set_script_timeout(time_to_wait / 1000.0)

def execute_script(self, script, *args):
return self.driver.execute_script(script, *args)

def execute_async_script(self, script, *args):
return self.driver.execute_async_script(script, *args)

def open(self, url):
self.driver.get(url)

def get_title(self):
return self.driver.title

def get_page_source(self):
return self.driver.page_source

def refresh(self):
self.driver.refresh()

def back(self):
self.driver.back()

def forward(self):
self.driver.forward()

def quit(self):
self.driver.quit()

def get_current_url(self):
return self.driver.current_url

def switch_to_frame(self, frame_reference):
self.driver.switch_to.frame(frame_reference)

def switch_to_parent_frame(self):
self.driver.switch_to.parent_frame()

def switch_to_default_content(self):
self.driver.switch_to.default_content()

def get_alert(self):
return self.driver.switch_to.alert

def get_cookies(self):
return self.driver.get_cookies()

def get_cookie(self, name):
return self.driver.get_cookie(name)

def delete_cookie(self, name):
self.driver.delete_cookie(name)

def delete_all_cookies(self):
self.driver.delete_all_cookies()

def add_cookie(self, cookie_dict):
self.driver.add_cookie(cookie_dict)

def get_screenshot_as_file(self, filename):
return self.driver.get_screenshot_as_file(filename)

def get_current_window_handle(self):
return self.driver.current_window_handle

def get_window_handles(self):
return self.driver.window_handles

def switch_to_window(self, window_reference):
self.driver.switch_to.window(window_reference)

def close_window(self, window_reference="current"):
if window_reference == "current":
self.driver.close()
else:
current_window = self.get_current_window_handle()
self.switch_to_window(window_reference)
self.driver.close()
self.switch_to_window(current_window)

def set_window_size(self, width, height, window_reference="current"):
self.driver.set_window_size(width, height, window_reference)

def get_window_size(self, window_reference="current"):
return self.driver.get_window_size(window_reference)

def set_window_position(self, x, y, window_reference="current"):
self.driver.set_window_position(x, y, window_reference)

def get_window_position(self, window_reference="current"):
return self.driver.get_window_position(window_reference)

def get_application_cache(self):
return self.driver.application_cache

def get_log_types(self):
return self.driver.log_types

def get_log(self, log_type):
return self.driver.get_log(log_type)

标签:return,get,self,driver,refactor,window,def
From: https://www.cnblogs.com/pangniu/p/17651383.html

相关文章

  • Google Chrome和ChromeDriver版本号不一致问题解决
    1(base)kaka@KakadeMBPbin%/Applications/Google\Chrome.app/Contents/MacOS/Google\Chrome--version2GoogleChrome116.0.5845.963(base)kaka@KakadeMBPbin%chromedriver--version4ChromeDriver114.0.5735.16(7e1ff058633f5b79b1cd7479aca585ba385......
  • 39 pinctrol(五)pinctrl client于pinctrl driver联系
    前言整体结构1.pinctrldirver于pinctrlclientplatform_driver与platform_device在匹配的过程中会调用really_probe在really_prebe中调用pinctrl_bind_pins(下图为pinctrl_bind_pins的大体实际框架)主要实现一下三个方面的功能pinctrl_map的创建或索引(bindpinsnowbefor......
  • python+playwright 学习-72 设置window.navigator.webdriver属性为false 跳过网站反爬
    前言有些网站有反爬机制,比如用代码启动的浏览器会被检测到,需要人机验证,用脚本去点击或者滑动滑动虽然能滑动,但是会认证失败。用playwright和selenium启动的浏览器都会用个webdriver属性。浏览器会根据这个属性判断是否是人工正常操作。window.navigator.webdriver属性人......
  • Clang参数中的-Xclang/-mllvm意义与Clang的Driver架构
    title:Clang参数中的-Xclang/-mllvm意义与Clang的Driver架构date:2023-08-1700:00:00updated:2023-08-1700:00:00lang:zh-CNcategories:-[LLVM]tags:-LLVM-编译toc:true文章首发于https://wwh1004.com/the-meaning-of-xclang-mllvm-in-clang-arguments-and-......
  • 软件测试|Chrome 115之后的版本,如何更新driver?
    2023年8月,chrome自动更新到115版本了,而从https://registry.npmmirror.com/binary.html?path=chromedriver/处只能下载114版本的driver,无法工作。参考:https://blog.csdn.net/Tester_muller/article/details/132086996  找到https://googlechromelabs.github.io/chrome-for......
  • webdriver 的三种等待方式(强制等待、隐式等待、显示等待)
    在自动化测试脚本的运行过程中,webdriver操作浏览器的时候,对于元素的定位是有一定的超时时间,大致应该在1-3秒的样子,如果这个时间内仍然定位不到元素,就会抛出异常,中止脚本执行。我们可以通过在脚本中设置等待的方式来避免由于网络延迟或浏览器卡顿导致的偶然失败,常用的等待方式有三......
  • 38 pinctrl(四)pinctrl driver
    前言一些使用技巧查看设备支持的pinctrlls/sys/kernel/debug/pinctrl/查看pinctrl中支持的引脚、组、functioncat/sys/kernel/debug/pinctrl/20e0000.iomuxc/pinscat/sys/kernel/debug/pinctrl/20e0000.iomuxc/pingroupscat/sys/kernel/debug/pinctrl/20e0000.io......
  • 当打开百度,定位输入报错怎么解决driver.find_element_by_id('kw').send_keys("seleniu
    报错如下: 解决方案,改变编写方式,引入fromselenium.webdriver.common.byimportBy  源码:例子说明: 打开百度,输入selenium进行搜索。fromseleniumimportwebdriverfromtimeimportsleepfromselenium.webdriver.common.byimportBydriver=webdriver.Chrome()d......
  • Golang - 原生go-sql-driver:出现invalid connection报错
    在使用go-sql-driver/msqyl驱动过程中,偶现invalidconnection错误,字面上看就是无效连接的意思。开始以为是数据库压力问题或是网络不好,后来发现服务器和数据库是走内网的,网络出现问题几率非常小;只是在测试服务器上跑,没多少连接,不存在压力问题。golang数据库驱动维护一个连接池,如......
  • ios自动化-Xcode、WebDriverAgent环境部署
    环境准备:Mac电脑一台(更新到最新的macOS,此文档使用的为macOS12.3.1,Intel芯片)Xcode最新稳定版(此文档使用的为13.4.1)IOS设备(此文档使用了10.3.3-15.1均有,且都安装WebDriverAgent成功)保证自己电脑有大于25G的可用内存空间,Xcode很大!Xcode下载https://developer.apple.com/xcode/r......