自动化测试
-
【iTestCat】测试Playwright脚本
编写测试代码 创建一个名为 test_itestcat.py 的文件,并写入以下代码:
123456789def test_itestcat(page):# 打开 itestcat.compage.goto("https://itestcat.com")# 验证页面标题assert "itestcat" in page.title()# 在页面中查找特定的元素 (可以根据需求调整)assert page.locator("text=首页").is_visible()运行测试 在终端中运行以下命令来执行测试: pytest test_itestcat.py 详细解释: page.goto() 用于让浏览器导航到指定的 URL,这里是 itestcat.com。 page.…
-
【iTestCat】通过 pytest 使用 Playwright
1. 安装 pytest 首先,你需要确保你的环境中安装了 pytest。如果没有安装,可以通过以下命令安装: pip install pytest 2. 安装 Playwright 及其 pytest 插件 为了使用 Playwright 进行测试,你需要安装 Playwright 和 pytest-playwright 插件。运行以下命令来安装: pip…
-
【iTestCat】通过Node.js安装Playwright
要安装 Playwright,按照以下步骤操作: 1. 安装 Node.js 首先,你需要确保你的系统上安装了 Node.js。你可以通过以下命令检查是否已安装 Node.js: node -v 如果没有安装,可以去 Node.js 官方网站 下载并安装。 2. 初始化项目 在你的项目目录中运行以下命令来初始化一个新项目: npm init -y 3. 安装…
-
【iTestCat】错误截图(selenium+python3教程)
在进行UI自动化测试时,你可能需要捕获程序执行错误时的截图,selenium提供获取浏览器截图的方法:
1driver.get_screenshot_as_file(“image.png”)实例:
123456789#捕捉百度输入框异常from selenium import webdriverdriver = webdriver.Chrome()driver.get("http://www.itestcat.com")try:driver.find_element_by_id("kw").send_keys("itestcat")driver.find_element_by_id("su").click()except:driver.get_screenshot_as_file("error_png.png") -
【iTestCat】操作cookie(selenium+python3教程)
在操作cookie前我们需要了解浏览器中是否存在某个cookie 信息,在验证浏览器中cookie是否正确时,有时基于真实cookie的测试是无法通过白盒和集成测试进行的。Webdriver提供了操作Cookie的相关方法,可以读取,添加和删除cookie信息。 webdriver操作cookie()的方法: get_cookies(): 获得所有cooki…
-
【iTestCat】主流浏览器启动控制台(selenium+python3教程)
1、IE浏览器 IE浏览器需要下载IEDriverServer并将driver所在路径配置至环境变量中。 下载地址:http://selenium-release.storage.googleapis.com/3.9/IEDriverServer_x64_3.9.0.zip 启动IE浏览器控制台代码如下:[crayon-67b5666e1021a483777…
-
【iTestCat】调用javaScript方法(selenium+python3教程)
execute_script(script, *args) 在当前窗口/框架同步执行javaScript script:JavaScript 的执行。 *args:适用任何JavaScript 脚本。 使用:
1driver.execute_script('document.title') -
【iTestCat】Appium通过uiautomatorviewer定位xpath元素
使用uiautomatorviewer可以抓取到的用来定位控件的元素大概有textresource-idcontent-descindex除此之外,appium还支持按Xpath来定位控件。 下载地址: 链接: https://pan.baidu.com/s/1hjAr5tbMXetJjYXgAjIxUA 密码: xnjs 安装和使用: 1. 将所有jar包…
-
【iTestCat】警告框弹窗处理(selenium+python3教程)
在WebDriver中处理JavaScript所生成的alert、confirm以及prompt十分简单,具体做法是使用 switch_to.alert 方法定位到 alert/confirm/prompt,然后使用text/accept/dismiss/ send_keys等方法进行操作。 text 返回alert/confirm/prompt 中的文字信…
-
【iTestCat】鼠标事件(selenium+python3教程)
ActionChains类鼠标操作的常用方法: context_click()右击 double_click()双击 drag_and_drop()拖动 move_to_element()鼠标悬停在一个元素上 click_and_hold()按下鼠标左键在一个元素上