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

合肥网站定制检测网站是否正常

合肥网站定制,检测网站是否正常,学院网站建设管理制度,wordpress菜单图标美化1.为什么使用go进行UI自动化测试#xff1f; 速度#xff1a;Go速度很快#xff0c;这在运行包含数百个UI测试的测试套件时是一个巨大的优势 并发性#xff1a;可以利用Go的内置并发性(goroutines)来并行化测试执行 简单#xff1a;Go的简约语法允许您编写可读且可维护… 1.为什么使用go进行UI自动化测试 速度Go速度很快这在运行包含数百个UI测试的测试套件时是一个巨大的优势 并发性可以利用Go的内置并发性(goroutines)来并行化测试执行 简单Go的简约语法允许您编写可读且可维护的测试脚本 ChromeDP一个无头Chrome/Chromium库允许直接从Go控制浏览器 2.什么是chromedp ChromeDP 是一个 Go 库允许开发者通过 Chrome DevTools 协议控制 Chrome/Chromium。借助 ChromeDP您可以与网页交互、模拟用户输入、浏览浏览器以及提取内容进行验证。它既可以在无头模式(没有浏览器UI)下工作也可以在有头模式(有可见浏览器)下工作。 3.设置环境 安装go brew install go 安装ChromeDP go get -u github.com/chromedp/chromedp 4.编写代码 示例测试 打开GoLand新建main.go文件 main.go-核心测试 这段代码将会打开Chrome导航到Google搜索页搜索Golang并验证Golang是否出现在搜索结果中 package mainimport (contextfmtgithub.com/chromedp/chromedpgithub.com/chromedp/chromedp/kblogstringstime )func main() {opts : chromedp.DefaultExecAllocatorOptions[:]opts append(opts,// Disable headless modechromedp.Flag(headless, false),// Enable GPU (optional)chromedp.Flag(disable-gpu, false),// Start with a maximized windowchromedp.Flag(start-maximized, true),)allocCtx, cancel : chromedp.NewExecAllocator(context.Background(), opts...)defer cancel()ctx, cancel : chromedp.NewContext(allocCtx)defer cancel()ctx, cancel context.WithTimeout(ctx, 15*time.Second)defer cancel()var result stringerr : chromedp.Run(ctx,chromedp.Navigate(https://www.google.com),chromedp.WaitVisible(//textarea[nameq]),chromedp.SendKeys(//textarea[nameq], Golang),chromedp.SendKeys(//textarea[nameq], kb.Enter),chromedp.WaitVisible(#search),chromedp.Text(#search, result),)if err ! nil {log.Fatal(err)}if strings.Contains(result, Golang) {fmt.Println(Test Passed: Golang found in search results)} else {fmt.Println(Test Failed: Golang not found in search results)} } Go测试框架编写多个UI测试 新建main_test.go文件 main_test.go-多种测试结果 测试用例 检查搜索结果是否包含术语“Golang”验证搜索栏是否在 Google 主页上可见检查空查询是否会导致没有搜索结果 package mainimport (contextgithub.com/chromedp/chromedpgithub.com/chromedp/chromedp/kbstringstestingtime )// checks that the search results contain Golang func TestGoogleSearch_Golang(t *testing.T) {opts : chromedp.DefaultExecAllocatorOptions[:]opts append(opts,chromedp.Flag(headless, false),chromedp.Flag(disable-gpu, false),chromedp.Flag(start-maximized, true),)allocCtx, cancel : chromedp.NewExecAllocator(context.Background(), opts...)defer cancel()ctx, cancel : chromedp.NewContext(allocCtx)defer cancel()ctx, cancel context.WithTimeout(ctx, 15*time.Second)defer cancel()var result stringerr : chromedp.Run(ctx,chromedp.Navigate(https://www.google.com),chromedp.WaitVisible(//textarea[nameq]),chromedp.SendKeys(//textarea[nameq], Golang),chromedp.SendKeys(//textarea[nameq], kb.Enter),chromedp.WaitVisible(#search),chromedp.Text(#search, result),)if err ! nil {t.Fatalf(Test Failed: %v, err)}if strings.Contains(result, Golang) {t.Log(Test Passed: Golang found in search results)} else {t.Errorf(Test Failed: Golang not found in search results)} }// checks that the search bar is visible func TestGoogleSearch_SearchBarVisible(t *testing.T) {opts : chromedp.DefaultExecAllocatorOptions[:]opts append(opts,chromedp.Flag(headless, false),chromedp.Flag(disable-gpu, false),chromedp.Flag(start-maximized, true),)allocCtx, cancel : chromedp.NewExecAllocator(context.Background(), opts...)defer cancel()ctx, cancel : chromedp.NewContext(allocCtx)defer cancel()ctx, cancel context.WithTimeout(ctx, 15*time.Second)defer cancel()err : chromedp.Run(ctx,chromedp.Navigate(https://www.google.com),chromedp.WaitVisible(//textarea[nameq]),)if err ! nil {t.Errorf(Test Failed: Search bar not visible - %v, err)} else {t.Log(Test Passed: Search bar is visible)} }// checks if there are results when the search query is empty func TestGoogleSearch_EmptyQuery(t *testing.T) {opts : chromedp.DefaultExecAllocatorOptions[:]opts append(opts,chromedp.Flag(headless, false),chromedp.Flag(disable-gpu, false),chromedp.Flag(start-maximized, true),)allocCtx, cancel : chromedp.NewExecAllocator(context.Background(), opts...)defer cancel()ctx, cancel : chromedp.NewContext(allocCtx)defer cancel()ctx, cancel context.WithTimeout(ctx, 15*time.Second)defer cancel()var result stringerr : chromedp.Run(ctx,chromedp.Navigate(https://www.google.com),chromedp.WaitVisible(//textarea[nameq]),chromedp.SendKeys(//textarea[nameq], ), // Empty querychromedp.SendKeys(//textarea[nameq], kb.Enter),chromedp.WaitVisible(#search, chromedp.ByID),chromedp.Text(#search, result),)if err ! nil {t.Fatalf(Test Failed: %v, err)}if result {t.Log(Test Passed: No search results for empty query)} else {t.Errorf(Test Failed: Unexpected results for empty query)} } 执行测试 将main.go和main_test.go放在同一目录然后执行命令 go test -v 测试结果
http://www.hkea.cn/news/14306220/

相关文章:

  • 网站建设内容的重点做网站构架
  • asp网站怎么验证到百度站长网页版抖音入口
  • 桂林北站是哪个区如何关闭网站 备案
  • 中国智慧团建网站传媒大气的网站
  • 南宁市网站开发建设建筑网站免费
  • 中国网站建设公司 排名最旺的公司名称大全
  • 广州黄埔网站建设网络公司网站策划书
  • 网站网址没有被百度收录重庆专业网站建设
  • 做挂件像网站网站实名认证中心
  • 定州网站建设公司沈阳哪个公司可以做网站
  • 视频网站建设价位计算机网络技专业术网站开发
  • 建立网站图片网站js时间代码
  • 济南地产行业网站开发苏州智能网站开发
  • 哪个网站帮忙做户型方案陕西的网站建设公司哪家好
  • 开远市新农村数字建设网站深圳市外贸公司
  • 网站建设视频vs百度推广登录网站
  • 建网站服务网站制作英文版网站
  • 做网站需要vps吗洛阳网站建设好做不
  • 顺德网站制作公司哪家好wordpress这
  • 鲜花网站建设策划方案游戏网站建设论文
  • 全国网站建设人员数量去越南做网站
  • 外贸网站设计案例中间商可以做网站吗
  • 网站是做流程苏州建网站皆去苏州聚尚网络
  • 搭建网站的过程在网上怎么注册公司
  • 一个网站的制作流程谁有国外hs网站
  • 网店的网站设计方案微信小程序开发步骤图
  • 做网站需要什么学历网站源代码上传
  • 企业网站建设作品分析网站一级域名和二级域名区别
  • 学校管理网站源码西安seo优化顾问
  • 哪些网站可以接生意做做瞹视频网站