最简单的Web Monkey 测试范例

简介: 最简单的Web Monkey 测试范例

大家好,我是阿萨,昨天学习了随机测试。立即搜索了随机测试的小工具。发现一个真正的傻瓜是的chrome 插件来做随机测试的。1. Chrome 插件欢迎从如下链接安装:https://chromeload.com/extension-41598-monkey-testing


安装完,开始应用,点开插件, 点Start 按钮。 随机测试就开始了。然后再点一下stop 就结束了。2. Playwright 可以测试输入框和按钮的小代码。使用Playwright 写一个小程序,随机生成小程序。


from playwright.sync_api import Playwright, sync_playwright
def fill_and_submit_form(page):    # Find all input fields on the page    input_fields = page.query_selector_all('input')
    # Fill in each input field with a unique value    for i, input_field in enumerate(input_fields):        input_field.fill(f'test{i}')
    # Find the submit button and click it    submit_button = page.query_selector('button[type="submit"]')    submit_button.click()
with sync_playwright() as playwright:    # Launch the browser and create a new page    browser = playwright.chromium.launch()    page = browser.new_page()
    # Navigate to the target web page    page.goto('https://example.com')
    # Fill in and submit the form on the page    fill_and_submit_form(page)
    # Close the browser    browser.close()


3. 可以测试Web页面所有组件的Monkey 测试工具使用如下代码可以测试所有页面上的随机组件。


import randomimport timefrom playwright.sync_api import Playwright, sync_playwright
def monkey_test_page(page, num_iterations):    # Define a list of action functions to perform on the page    actions = [click_random_element, fill_random_input, navigate_random_link]
    for i in range(num_iterations):        # Randomly choose an action function from the list        action = random.choice(actions)
        # Perform the chosen action on the page        action(page)
        # Wait for a random amount of time between actions        time.sleep(random.uniform(0.5, 1.5))
def click_random_element(page):    # Find all clickable elements on the page    clickable_elements = page.query_selector_all('a, button')
    # Randomly choose an element and click it    random_element = random.choice(clickable_elements)    random_element.click()
def fill_random_input(page):    # Find all input fields on the page    input_fields = page.query_selector_all('input[type="text"], input[type="password"], textarea')
    # Randomly choose an input field and fill it with a random string    random_input = random.choice(input_fields)    random_input.fill(''.join(random.choices('abcdefghijklmnopqrstuvwxyz', k=10)))
def navigate_random_link(page):    # Find all links on the page    links = page.query_selector_all('a')
    # Randomly choose a link and navigate to it    random_link = random.choice(links)    page.goto(random_link.get_attribute('href'))
with sync_playwright() as playwright:    # Launch the browser and create a new page    browser = playwright.chromium.launch()    page = browser.new_page()
    # Navigate to the target web page    page.goto('https://example.com')
    # Perform monkey testing on the page for 10 iterations    monkey_test_page(page, 10)
    # Close the browser    browser.close()


赶紧用起来吧,来测试下自己的Web应用。

相关文章
|
2月前
|
SQL 安全 测试技术
Web应用程序安全测试
Web应用程序安全测试
|
2月前
|
Web App开发 编解码 前端开发
面试题22:如何测试Web浏览器的兼容性?
面试题22:如何测试Web浏览器的兼容性?
|
6天前
|
XML Web App开发 测试技术
python的Web自动化测试
【4月更文挑战第16天】Python在Web自动化测试中广泛应用,借助Selenium(支持多浏览器交互)、BeautifulSoup(解析HTML/XML)、Requests(发送HTTP请求)和Unittest(测试框架)等工具。测试步骤包括环境搭建、编写测试用例、初始化浏览器、访问页面、操作元素、验证结果、关闭浏览器及运行报告。注意浏览器兼容性、动态内容处理和错误处理。这些组合能提升测试效率和质量。
11 6
|
1月前
|
监控 安全 Shell
深入探究App压力测试的关键要点:从零开始学习Monkey
Monkey是Google的自动化测试工具,用于模拟用户随机事件以测试应用的稳定性和压力。它可以在模拟器或设备上运行,通过随机点击发现潜在问题。
27 1
|
1月前
javaWeb服务详解(含源代码,测试通过,注释) ——web.xml
javaWeb服务详解(含源代码,测试通过,注释) ——web.xml
7 0
|
1月前
|
安全 测试技术 API
请描述在 Python WEB 开发中常用的测试方法。
请描述在 Python WEB 开发中常用的测试方法。
18 0
|
1月前
|
Web App开发 前端开发 测试技术
Web应用程序测试工具Selenium用法详解
Web应用程序测试工具Selenium用法详解
37 0
|
2月前
|
Web App开发 测试技术 数据安全/隐私保护
Web自动化测试工具Selenium
Web自动化测试工具Selenium
|
2月前
|
人工智能 前端开发 Java
软件测试/人工智能|熟练使用web控件定位技巧,提升测试工作效率!
软件测试/人工智能|熟练使用web控件定位技巧,提升测试工作效率!
197 1
|
2月前
|
编解码 缓存 前端开发
Web浏览器的兼容性测试需要考虑哪些测试点?
Web浏览器的兼容性测试需要考虑哪些测试点?