几种常用基于GUI的测试工具比对

Selenium   
代码

test_by_selenium.py   

# coding=utf-8
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from util import drivers
import pytest
from selenium.webdriver.common.by import By
          

class TestSelenium():
       def setup(self):
              d = drivers()
              self.driver=d.driver
              self.driver.get("http://www.baidu.com")
          

       def test_baidu(self):
              inputElement = self.driver.find_element(By.NAME, "wd")
              inputElement.send_keys("软件测试")
              inputElement.submit()
              WebDriverWait(self.driver, 20).until(lambda driver: driver.title.startswith("软件测试"))
              assert self.driver.title.startswith("软件测试")
          

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

if __name__ == '__main__':
pytest.main(["-v", "TestSelenium.py"])

 util.py  

#!/usr/bin/env python
#coding:utf-8
from selenium import webdriver
import time
from selenium.webdriver.edge.service import Service
          

class drivers:
       def __init__(self):
              f = open("info.txt", "r")
              driverPach = "C:\\Lib\\";
              brower = f.readline()
              f.close()
              if brower.lower() == "ie":
                     service = Service(executable_path=driverPach+"IEDriverServer.exe")
                     options = webdriver.IEOptions()
              elif brower.lower() == "firefox":
                     service = Service(executable_path=driverPach+"geckodriver.exe")
                     options = webdriver.FirefoxOptions()
              elif brower.lower() == "chrome":
                     service = Service(executable_path=driverPach+"chromedriver.exe")
                     options = webdriver.ChromeOptions()
              elif brower.lower() == "edge":
                     service = Service(executable_path=driverPach+"msedgedriver.exe")
                     options = webdriver.EdgeOptions()
              else:
                     print("info.txt中的信息有误")
              options.add_argument('--start-maximized')
              options.service = service
              if brower.lower() == "ie":
                     self.driver = webdriver.IE(options=options)
              elif brower.lower() == "firefox":
                     self.driver = webdriver.Firefox(options=options)
              elif brower.lower() == "chrome":
                     self.driver = webdriver.Chrome(options=options)
              elif brower.lower() == "edge":
                     self.driver = webdriver.Edge(options=options)
              else:
                      print("info.txt中的信息有误")
              self.driver.maximize_window()

Playwright  

代码

import pytest
from playwright.sync_api import Page
          

def test_baidu(page: Page):
    inputStr="软件测试"
    page.goto("https://www.baidu.com/")
    page.locator("#kw").click()
    page.locator("#kw").fill(inputStr)
    page.get_by_role("button", name="百度一下").click()
    page.wait_for_selector('span[class="hint_PIwZX c_font_2AD7M"]',state='attached')
    assert page.title() == inputStr+ '_百度搜索'
    assert page.text_content('#s_tab>div>a.s-tab-item.s-tab-item_1CwH-.s-tab-pic_p4Uej.s-tab-pic') == '图片'
    page.close()
if __name__ == '__main__':
pytest.main(["-v", "TestPlaywright.py"])

​​​​​​cypress  

describe('百度',function(){
       context('百度测试',function(){
              it('进入百度成功,输入软件测试',function (){
                     cy.visit('https://www.baidu.com/')
                     cy.get('#kw').type('软件测试')
                     cy.get('#su').click()
                     cy.get('a[name="tj_settingicon"]').should('contain', '设置')
              })
       })
})

结果  

                 

第1次

第2次

第3次

第4次

第5次

平均

selenium

6.99s 

6.90s 

6.93s

6.73s

6.90s

6.87s

Playwright

4.23s 

4.23s 

4.42s

4.24s

4.35s

4.29s

cypress

5s

4s

5s

5s         

4s

4.6s

由此可见,selenium运行速度最慢,Playwright与cypress速度相当​​​​​​​

最后:下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

在这里插入图片描述

软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

图片

整套资料获取

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值