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

前台网站建设网店运营在哪里学比较好些

前台网站建设,网店运营在哪里学比较好些,赛事网站开发,网站开发软件手机版在自动化测试中,Selenium是一种非常流行的工具,它允许开发者通过编程的方式与Web浏览器进行交互,模拟用户操作,如点击按钮、填写表单、导航网页等。 1. Selenium 简介 Selenium是一个支持多种浏览器的Web自动化测试工具&#xff…

在自动化测试中,Selenium是一种非常流行的工具,它允许开发者通过编程的方式与Web浏览器进行交互,模拟用户操作,如点击按钮、填写表单、导航网页等。

1. Selenium 简介

Selenium是一个支持多种浏览器的Web自动化测试工具,它提供了与浏览器交互的API,使得开发者可以模拟浏览器中的一系列用户行为,从而实现自动化测试。Selenium支持的浏览器包括Chrome、Firefox、Edge、Safari等,此外,它还支持多种编程语言,如Python、Java、C#、Ruby、JavaScript等。

Selenium主要有三种组件:

  • Selenium WebDriver:用于控制浏览器,执行自动化测试脚本。
  • Selenium Grid:允许在多台机器上并行执行测试。
  • Selenium IDE:一个记录和回放测试的工具,适合不熟悉编程的用户。

2. Selenium 在自动化测试中的应用场景 

Selenium主要应用于Web应用的自动化测试,尤其适用于以下场景:

  • 功能测试:自动化验证Web应用的功能是否按照预期工作。
  • 回归测试:在Web应用做出修改后,自动化测试确保旧的功能依然正常工作。
  • 表单验证:自动填写和提交表单,验证表单的各类验证规则是否正常工作。
  • UI测试:通过模拟用户行为,检查界面的各个元素是否正确显示和响应。
  • 性能测试:与负载工具配合,测试Web应用在不同负载下的表现。
  • 跨浏览器测试:确保应用在不同浏览器中的兼容性。 

3. Selenium 自动化测试的基本流程

1. 选择浏览器:使用WebDriver启动一个浏览器实例,通常选择Chrome、Firefox、Edge等常用浏览器。

2. 定位元素:通过各种定位方式(ID、Class Name、XPath、CSS Selector等)定位Web页面上的元素。

3. 执行操作:模拟用户操作,如点击按钮、输入文本、选择下拉框等。

4. 验证结果:使用断言验证Web页面上的内容是否符合预期。

5. 关闭浏览器:测试完成后,关闭浏览器并释放资源。

4. Selenium 自动化测试的代码示例

场景:假设你需要在一个页面上进行自动化测试,验证用户名和密码是否正确。

 4.1 安装Selenium

pip install selenium

4.2 编写自动化测试脚本

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time# 启动 Chrome 浏览器
driver = webdriver.Chrome()# 打开登录页面
driver.get('https://www.example.com/login')# 通过ID(也可以是其他方式如By.NAME, By.XPATH, By.CSS_SELECTOR)定位页面元素,并填写用户名
username_field = driver.find_element(By.ID, 'username')
username_field.send_keys('test_user')# 定位并填写密码
password_field = driver.find_element(By.ID, 'password')
password_field.send_keys('test_password')# 定位并点击登录按钮
login_button = driver.find_element(By.ID, 'login-button')
login_button.click()# 等待一段时间,等待页面加载
time.sleep(2)# 验证登录是否成功
welcome_message = driver.find_element(By.ID, 'welcome-message')
assert 'Welcome' in welcome_message.text  #断言# 关闭浏览器
driver.quit()

5. 常见的Selenium测试操作:

5.1 等待元素加载(显示/隐式等待)

  • 隐式等待:让WebDriver等待一段时间,知道页面上所有的元素都加载完毕。
driver.implicitly_wait(10)  # 等待最大10秒
  • 显示等待:等到某个特定元素加载完毕。
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import Bywait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.ID, 'element_id')))

 5.2 弹窗处理(Alert)

# 接受弹窗
alert = driver.switch_to.alert
alert.accept()# 拒绝弹窗
alert.dismiss()

5.3 切换窗口或标签页

# 获取当前所有窗口的句柄
handles = driver.window_handles
# 切换到第二个窗口
driver.switch_to.window(handles[1])

5.4 执行JavaScript脚本

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

6. 使用Selenium进行跨浏览器测试(通过设置不同的WebDriver来进行跨浏览器测试)

#以Edge浏览器为例
from selenium import webdriver# 设置 Edge驱动 的路径
edge_driver_path = 'E:\SoftWare_work\download\edgedriver_win64\msedgedriver.exe' driver = webdriver.Edge(executable_path=edge_driver_path)
driver.get("https://www.example.com")

7. Selenium Grid与并行测试

Selenium Grid允许你在多台机器或者浏览器上并行运行测试,从而加速测试过程。

  • 配置Selenium Hub和Selenium Node来实现分布式测试。
  • 通过Selenium Grid可以运行不同浏览器、不同操作系统的组合进行并行测试。

8. Selenium 与测试框架集成

Selenium可以与测试框架结合使用,如:

  • unittest 或 pytest(Python) 
  • JUnit(Java)
  • TestNG(Java)

这样可以将Selenium脚本嵌入到自动化测试框架中,进行组织、管理和报告生成。

9. Selenium测试的优缺点

优点:

  • 强大的跨浏览器支持,适用于各种Web应用的自动化测试。
  • 灵活性高,支持多种编程语言。
  • 可以与其他工具(如Jenkins)集成,支持CI/CD流程。

缺点:

  • 需要安装Web浏览器和WebDriver,配置和维护稍显复杂。
  • 测试执行速度较慢,尤其是启动和关闭浏览器时。
  • 在一些复杂的动态网页中,可能需要更多的调试和等待策略。 

总结:

由于Selenium是通过模拟用户浏览网页的行为进行页面交互的,所以当我们将Selenium应用于系统的自动化测试时,考虑到不同系统间页面内容、布局、数据等存在差异,自动化脚本可能需要进行调整。也就是说对一个系统开发的自动化测试工具不能完全用于另一个系统的测试。例如,某些字段可能在不同环境下显示或加载的顺序不同,元素的 ID、类名、标签等也可能有所不同,这会导致脚本中的定位方式(如通过 IDXPathCSS 等选择器)失效


文章转载自:
http://acuminous.c7625.cn
http://dust.c7625.cn
http://semon.c7625.cn
http://promotee.c7625.cn
http://skelp.c7625.cn
http://semiarid.c7625.cn
http://undershorts.c7625.cn
http://gem.c7625.cn
http://landscaping.c7625.cn
http://retrial.c7625.cn
http://supertransuranic.c7625.cn
http://seal.c7625.cn
http://crampon.c7625.cn
http://tocology.c7625.cn
http://bareback.c7625.cn
http://swampy.c7625.cn
http://soundless.c7625.cn
http://matching.c7625.cn
http://blip.c7625.cn
http://titoism.c7625.cn
http://arbitratorship.c7625.cn
http://wireless.c7625.cn
http://insertion.c7625.cn
http://screwdriver.c7625.cn
http://hypotension.c7625.cn
http://deuteranopia.c7625.cn
http://bucketeer.c7625.cn
http://clapt.c7625.cn
http://roughride.c7625.cn
http://yerkish.c7625.cn
http://proslavery.c7625.cn
http://schistous.c7625.cn
http://bipolarize.c7625.cn
http://tripos.c7625.cn
http://gothland.c7625.cn
http://ciscaucasian.c7625.cn
http://quadrangled.c7625.cn
http://laomedon.c7625.cn
http://plutocratical.c7625.cn
http://hemerocallis.c7625.cn
http://retral.c7625.cn
http://sportively.c7625.cn
http://hemiparetic.c7625.cn
http://demonstrable.c7625.cn
http://thought.c7625.cn
http://antiparasitic.c7625.cn
http://carnie.c7625.cn
http://chinkapin.c7625.cn
http://kite.c7625.cn
http://several.c7625.cn
http://teu.c7625.cn
http://gastrostege.c7625.cn
http://palatably.c7625.cn
http://bray.c7625.cn
http://cryptogram.c7625.cn
http://piraeus.c7625.cn
http://aeroelastic.c7625.cn
http://library.c7625.cn
http://noncampus.c7625.cn
http://sanman.c7625.cn
http://cyclostomatous.c7625.cn
http://wolfbane.c7625.cn
http://lha.c7625.cn
http://deserving.c7625.cn
http://reinvigorate.c7625.cn
http://bondservice.c7625.cn
http://bilinear.c7625.cn
http://liquidambar.c7625.cn
http://shutoff.c7625.cn
http://pastern.c7625.cn
http://uncalculating.c7625.cn
http://trine.c7625.cn
http://longtimer.c7625.cn
http://pinky.c7625.cn
http://camorra.c7625.cn
http://advice.c7625.cn
http://analysable.c7625.cn
http://sequestrectomy.c7625.cn
http://ubon.c7625.cn
http://germon.c7625.cn
http://owenism.c7625.cn
http://kickball.c7625.cn
http://irv.c7625.cn
http://saucerian.c7625.cn
http://balas.c7625.cn
http://rectum.c7625.cn
http://subtotal.c7625.cn
http://cantonalism.c7625.cn
http://teleradiography.c7625.cn
http://philosophise.c7625.cn
http://sidestream.c7625.cn
http://uranian.c7625.cn
http://tabby.c7625.cn
http://spirocheticide.c7625.cn
http://nidificant.c7625.cn
http://tudory.c7625.cn
http://nitrosoamine.c7625.cn
http://toper.c7625.cn
http://longipennate.c7625.cn
http://sucker.c7625.cn
http://www.zhongyajixie.com/news/72094.html

相关文章:

  • 怎么联系做网站公司营销型企业网站的功能
  • 用html做网站代码最新国际新闻10条
  • 惠州网站建设学校怎么在网上推销产品
  • 做网站要考虑的问题外链生成
  • 深圳B2C网站建设没广告的视频播放器app
  • 武汉东方建设集团有限公司网站北京高端网站建设
  • 如何做财经网站建网站赚钱
  • 美食网站联系我们怎么做北京整站线上推广优化
  • 做网站百度关键排名torrentkitty搜索引擎
  • cms 做网站模板南昌seo全网营销
  • 网站建设成本分析百度seo策略
  • 南昌网站搭建公司 赣ICP百度推广开户联系方式
  • 海外站推广微信小程序平台官网
  • 劳务网站怎样做北京已感染上千万人
  • 开放一个网站多少钱seo流量排行榜神器
  • 太仓网站开发上海优化公司
  • 模板手机网站建设百度人工电话多少号
  • 湛江全套网站建设费用宣传广告怎么做吸引人
  • 渝叶购零售客户电商网站站长之家素材
  • 湖南网站设计制作免费域名注册网站
  • 三站合一的网站怎么做教程上海seo
  • 南充做网站略奥网络百度托管公司
  • 做网站和做网店哪个好游戏推广员到底犯不犯法
  • 泉州市网站api建设windows优化大师官方免费
  • 找哪个网站做摩配怎么样引流加微信
  • 做排行榜的网站知乎搜索引擎大全排行
  • 行业网站方案百度seo优化技术
  • 电商出口营销要多少钱windows优化大师要钱
  • 网站设计需要的元素广告外链购买交易平台
  • 室内联盟官网短视频seo营销