当前位置: 首页 > news >正文

网站建设经济效益网站优化费用报价明细

网站建设经济效益,网站优化费用报价明细,基于dw的网站设计论文,百度外推排名代做目录 1、selenium版本的演变 1.1、Selenium 1.x#xff08;Selenium RC时代#xff09; 1.2、Selenium 2.x#xff08;WebDriver整合时代#xff09; 1.3、Selenium 3.x 2、selenium原理说明 3、源码说明 3.1、启动webdriver服务建立连接 3.2、发送操作 1、seleni…目录 1、selenium版本的演变 1.1、Selenium 1.xSelenium RC时代 1.2、Selenium 2.xWebDriver整合时代 1.3、Selenium 3.x 2、selenium原理说明 3、源码说明 3.1、启动webdriver服务建立连接 3.2、发送操作 1、selenium版本的演变 1.1、Selenium 1.xSelenium RC时代 核心原理 Selenium RCRemote ControlSelenium 1.x主要通过Selenium RC来实现自动化测试。Selenium RC启动一个Server该Server负责控制浏览器行为。JavaScript注入技术Selenium RC将操作Web元素的API调用转化为JavaScript代码然后通过Selenium Core一堆JavaScript函数的集合注入到浏览器中执行。这种方式依赖于浏览器对JavaScript的支持但速度较慢且稳定性依赖于Selenium内核对API的JavaScript翻译质量。 1.2、Selenium 2.xWebDriver整合时代 核心原理 WebDriver的引入Selenium 2.x整合了WebDriver项目使得Selenium更加强大。WebDriver利用浏览器原生的API封装成一套面向对象的Selenium WebDriver API直接操作浏览器页面里的元素甚至操作浏览器本身如截屏、窗口大小调整、启动/关闭浏览器等。浏览器原生API由于使用浏览器原生APIWebDriver的速度大大提升且调用的稳定性交给了浏览器厂商本身。然而不同浏览器厂商对Web元素的操作和呈现存在差异因此WebDriver需要为不同浏览器提供不同的实现如ChromeDriver、FirefoxDriver等。WebDriver Wire协议WebDriver启动后会在特定端口上启动基于WebDriver Wire协议的Web Service所有对WebDriver的API调用都会通过HTTP请求发送给这个Web Service。 1.3、Selenium 3.x 核心原理 继承2.x的特性Selenium 3.x在底层原理上与Selenium 2.x保持一致继续利用WebDriver和浏览器原生API进行操作。新增特性Selenium 3.x加入了对更多浏览器原生驱动的支持如Edge和Safari的原生驱动以及更新了对Firefox的支持通过geckodriver。移除Selenium RC与Selenium 2.x相比Selenium 3.x去除了Selenium RC组件更加专注于WebDriver的使用。 新增功能和API为了满足用户不断变化的需求Selenium会引入新的功能和API以支持更复杂的测试场景和用例。 2、selenium原理说明 说明这里说的原理都是整合了WebDriver之后的selenium版本。 思考selenium是如何驱动浏览器做各种操作的呢 分析 首先我们想想我们可以直接和浏览器交互吗显然是不能这时候就需要借助一个代理人帮我们做这件事这个代理人就是WebDriver我们不知道浏览器内核的各种API难道浏览器厂商还不知道吗所以他们就提供这样一个代理人给我们使用。也就是我们现在知道WebDriver提供一个服务我们去请求这个服务把对浏览器的操作通过HTTP请求发送给WebDriver这个服务再由它把操作解析后去调用浏览器的API最终结果原路返回。这个时候我们还需要把这些操作统一起来才行不然不太可能我们自己总是去调用接口发送请求吧这时候selenium client就出现了它在内部帮我们处理好了底层通信的一切还把对浏览器的操作统一封装成一个个函数供给我们操作我们只需要关心操作和操作返回的结果就行。综上就是整个selenium做的事情了。 把上面的过程在提炼一下流程如下 1.对于每一条Selenium脚本一个http请求会被创建并且发送给浏览器的驱动最开始建立连接时服务端返回一个sessionid给客户端后续的交互都是通过sessionid进行交互2.浏览器驱动中包含了一个HTTP Server用来接收这些http请求3.HTTP Server接收到请求后根据请求来具体操控对应的浏览器4.浏览器执行具体的测试步骤5.浏览器将步骤执行结果返回给HTTP Server6.HTTP Server又将结果返回给Selenium的脚本如果是错误的http代码我们就会在控制台看到对应的报错信息。 3、源码说明 说明我们从源码的角度看看底层是如何进行交互的 3.1、启动webdriver服务建立连接 代码如下 from selenium import webdriverdriver_path E:\PycharmProjects\webUiTest\env\Scripts\chromedriver driver webdriver.Chrome(executable_pathdriver_path) 1、我们看看代码webdriver.Chrome(executable_pathdriver_path)做了什么事情按住ctrl键点击Chrome进入源码查看 def __init__(self, executable_pathchromedriver, port0,optionsNone, service_argsNone,desired_capabilitiesNone, service_log_pathNone,chrome_optionsNone, keep_aliveTrue):if chrome_options:warnings.warn(use options instead of chrome_options,DeprecationWarning, stacklevel2)options chrome_optionsif options is None:# desired_capabilities stays as passed inif desired_capabilities is None:desired_capabilities self.create_options().to_capabilities()else:if desired_capabilities is None:desired_capabilities options.to_capabilities()else:desired_capabilities.update(options.to_capabilities())self.service Service(executable_path,portport,service_argsservice_args,log_pathservice_log_path)self.service.start()try:RemoteWebDriver.__init__(self,command_executorChromeRemoteConnection(remote_server_addrself.service.service_url,keep_alivekeep_alive),desired_capabilitiesdesired_capabilities)except Exception:self.quit()raiseself._is_remote False 2、我们知道webdriver.Chrome()就是建立服务连接的过程所以我们看到建立服务相关的代码就是 我们在进入到self.service.start()源码看看它做了什么源码如下 def start(self):Starts the Service.:Exceptions:- WebDriverException : Raised either when it cant start the serviceor when it cant connect to the servicetry:cmd [self.path]cmd.extend(self.command_line_args())self.process subprocess.Popen(cmd, envself.env,close_fdsplatform.system() ! Windows,stdoutself.log_file,stderrself.log_file,stdinPIPE)except TypeError:pass 3、原来是通过subprocess.Popen()函数根据我们传过来的chromedriver路径开启一个子进程来执行打开chromedriver服务的命令。 4、但是别急到这里只是把webdriver服务开启了还没有初始化driver对象继续回到源码初始化driver对象肯定是在开启服务之后也就是下面的源码 5、我们继续进入看看它做了什么事情 def __init__(self, command_executorhttp://127.0.0.1:4444/wd/hub,desired_capabilitiesNone, browser_profileNone, proxyNone,keep_aliveFalse, file_detectorNone, optionsNone):Create a new driver that will issue commands using the wire protocol.capabilities {}if options is not None:capabilities options.to_capabilities()if desired_capabilities is not None:if not isinstance(desired_capabilities, dict):raise WebDriverException(Desired Capabilities must be a dictionary)else:capabilities.update(desired_capabilities)if proxy is not None:warnings.warn(Please use FirefoxOptions to set proxy,DeprecationWarning, stacklevel2)proxy.add_to_capabilities(capabilities)self.command_executor command_executorif type(self.command_executor) is bytes or isinstance(self.command_executor, str):self.command_executor RemoteConnection(command_executor, keep_alivekeep_alive)self._is_remote Trueself.session_id Noneself.capabilities {}self.error_handler ErrorHandler()self.start_client()if browser_profile is not None:warnings.warn(Please use FirefoxOptions to set browser profile,DeprecationWarning, stacklevel2)self.start_session(capabilities, browser_profile)self._switch_to SwitchTo(self)self._mobile Mobile(self)self.file_detector file_detector or LocalFileDetector() 从注释可以看出这里主要是创建一个新的WebDriver实例它将使用WebDriver协议来发送命令给浏览器。使用对应变量保存相关初始化需要的参数然后开启一个会话session与webdriver建立通信我们看看最重要的部分也就是开启会话调用的函数 def start_session(self, capabilities, browser_profileNone):Creates a new session with the desired capabilities.if not isinstance(capabilities, dict):raise InvalidArgumentException(Capabilities must be a dictionary)if browser_profile:if moz:firefoxOptions in capabilities:capabilities[moz:firefoxOptions][profile] browser_profile.encodedelse:capabilities.update({firefox_profile: browser_profile.encoded})w3c_caps _make_w3c_caps(capabilities)parameters {capabilities: w3c_caps,desiredCapabilities: capabilities}response self.execute(Command.NEW_SESSION, parameters) 可以看到start_session()函数里面发送请求是self.execute()函数我们继续进入看看 def execute(self, driver_command, paramsNone):Sends a command to be executed by a command.CommandExecutor.if self.session_id is not None:if not params:params {sessionId: self.session_id}elif sessionId not in params:params[sessionId] self.session_idparams self._wrap_value(params)response self.command_executor.execute(driver_command, params)if response:print(打印响应参数, json.dumps(response, indent4))self.error_handler.check_response(response)response[value] self._unwrap_value(response.get(value, None))return response# If the server doesnt send a response, assume the command was# a successreturn {success: 0, value: None, sessionId: self.session_id}通过源码的值它主要是通过CommandExecutor发送一个请求这里我们把响应的结果打印到控制台看看这里的响应返回了什么新增一行输出代码如下 我们在进入到self.command_executor.execute(driver_command, params)函数看看是怎么把请求发送出去的 def execute(self, command, params):Send a command to the remote server.Any path subtitutions required for the URL mapped to the command should beincluded in the command parameters.command_info self._commands[command]assert command_info is not None, Unrecognised command %s % commandpath string.Template(command_info[1]).substitute(params)if hasattr(self, w3c) and self.w3c and isinstance(params, dict) and sessionId in params:del params[sessionId]data utils.dump_json(params)url %s%s % (self._url, path)return self._request(command_info[0], url, bodydata) 这里还是没有看到它到底是怎么把请求发送出去的继续进入到self._request(command_info[0], url, bodydata)函数 def _request(self, method, url, bodyNone):Send an HTTP request to the remote server.LOGGER.debug(%s %s %s % (method, url, body))parsed_url parse.urlparse(url)headers self.get_remote_connection_headers(parsed_url, self.keep_alive)resp Noneif body and method ! POST and method ! PUT:body Noneprint(f请求参数url: {url} \n body: {body} \n headers: {json.dumps(headers, indent4)})if self.keep_alive:resp self._conn.request(method, url, bodybody, headersheaders)statuscode resp.statuselse:http urllib3.PoolManager(timeoutself._timeout)resp http.request(method, url, bodybody, headersheaders) 终于到这里看到了它底层是通过urllib3库来发送http请求的这里我们把请求的参数打印出来 我们再次运行下面的代码看看请求参数和响应结果是什么 from selenium import webdriverdriver_path E:\PycharmProjects\webUiTest\env\Scripts\chromedriver driver webdriver.Chrome(executable_pathdriver_path) 输出结果如下 请求参数url: http://127.0.0.1:59146/session body: {capabilities: {firstMatch: [{}], alwaysMatch: {browserName: chrome, platformName: any, goog:chromeOptions: {extensions: [], args: []}}}, desiredCapabilities: {browserName: chrome, version: , platform: ANY, goog:chromeOptions: {extensions: [], args: []}}} headers: {Accept: application/json,Content-Type: application/json;charsetUTF-8,User-Agent: selenium/3.141.0 (python windows),Connection: keep-alive } 打印响应参数 {value: {capabilities: {acceptInsecureCerts: false,browserName: chrome,browserVersion: 127.0.6533.100,chrome: {chromedriverVersion: 127.0.6533.119 (bdef6783a05f0b3f885591e7d2c7b2aec1a89dea-refs/branch-heads/6533{#1999}),userDataDir: C:\\Users\\\u5218\u519b\\AppData\\Local\\Temp\\scoped_dir13212_999079333},fedcm:accounts: true,goog:chromeOptions: {debuggerAddress: localhost:59154},networkConnectionEnabled: false,pageLoadStrategy: normal,platformName: windows,proxy: {},setWindowRect: true,strictFileInteractability: false,timeouts: {implicit: 0,pageLoad: 300000,script: 30000},unhandledPromptBehavior: dismiss and notify,webauthn:extension:credBlob: true,webauthn:extension:largeBlob: true,webauthn:extension:minPinLength: true,webauthn:extension:prf: true,webauthn:virtualAuthenticators: true},sessionId: 34680a6d180d4c8f0a7225d00f92111f} }终于我们可以看到初始化建立会话是通过请求url: http://127.0.0.1:59146/session  然后返回sessionId后续操作都会携带该sessionId请求这样对应webdriver它才知道来自那个请求从而实现会话保持至此终于把会话建立了后续就可以通过这个会话发送操作了。 3.2、发送操作 前言通过上面的终于把会话建立了现在我们就需要通过会话发送操作命令了我们执行下面的代码看看这个过程是怎么的 driver.get(https://www.baidu.com) 运行结果如下 driver.get()做的事就是把get操作转换为对应的url地址然后通过携带sessionId发送请求到webdriver服务端也就是说driver.xxx()的每一个操作都对应了一个url地址这里肯定有个映射关系来维持进入源码查看不难找到在RemoteConnection这个类中维护了这样的关系
http://www.hkea.cn/news/14418089/

相关文章:

  • wordpress 网站图标设置购物网站 页面设计
  • 东莞免费网站建设网络营销网站模块是指什么地方
  • 企业做营销网站百度定位店铺位置怎么设置
  • 网站建设与管理学的是什么网站dns解析设置
  • 网站换域名seo保定最大的网络公司
  • 文山 网站建设 滇icp建筑人才培训网
  • 奉节网站建设宁波做网站的大公司
  • 网站建设南通企业网站app开发平台
  • 西安制作网站的电话网站收录方法
  • 黑龙江住房和建设厅网站网站开发竞品分析
  • 专业做网站的公司哪家好网站建设需要的软件是什么
  • 织梦唯美网站源码优化制造业布局
  • 电子商务网站的建设包含哪些流程做网站考虑的方面
  • 重庆点优建设网站公司河北涞水建设厅官方网站
  • 网站seo设计方案案例手机上怎么做自己的网站
  • 刚创业 建网站深圳做网页
  • 源码网站大淘客cms网页版ps
  • 网站开发参考文献格式灯罩技术支持东莞网站建设
  • 外贸企业网站功能要求大良建站公司行业现状
  • 开发网站和电脑软件的区别中国新闻最新消息大事件
  • 网站seo的方法济南商城网站建设公司
  • 怎么帮网站做支付接口福州做网站公司排名
  • 网站建设优化方法 swordpress 订阅号 采集
  • 潍坊网站建设咨询做百度推广效果怎么样
  • 中原区快速建站公司电话南昌的网站设计
  • 石家庄网络建站有谁认识做微网站的
  • 网站建设公司源码 asp网页游戏排行榜对战
  • wordpress 验证码插件西宁seo网站建设
  • asp网站开发源码有.net源码如何做网站
  • 北京工程建设合同备案网站凡客诚品来源