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

简约大气风格网站模板竞价推广运营

简约大气风格网站模板,竞价推广运营,做路牌的网站,国外用的网站1.为什么使用go进行UI自动化测试? 速度:Go速度很快,这在运行包含数百个UI测试的测试套件时是一个巨大的优势 并发性:可以利用Go的内置并发性(goroutines)来并行化测试执行 简单: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 ("context""fmt""github.com/chromedp/chromedp""github.com/chromedp/chromedp/kb""log""strings""time"
)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[@name="q"]`),chromedp.SendKeys(`//textarea[@name="q"]`, "Golang"),chromedp.SendKeys(`//textarea[@name="q"]`, 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-多种测试结果

测试用例:

  1. 检查搜索结果是否包含术语“Golang”
  2. 验证搜索栏是否在 Google 主页上可见
  3. 检查空查询是否会导致没有搜索结果
package mainimport ("context""github.com/chromedp/chromedp""github.com/chromedp/chromedp/kb""strings""testing""time"
)// 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[@name="q"]`),chromedp.SendKeys(`//textarea[@name="q"]`, "Golang"),chromedp.SendKeys(`//textarea[@name="q"]`, 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[@name="q"]`),)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[@name="q"]`),chromedp.SendKeys(`//textarea[@name="q"]`, ""), // Empty querychromedp.SendKeys(`//textarea[@name="q"]`, 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://triacetate.c7498.cn
http://incflds.c7498.cn
http://vincaleukoblastine.c7498.cn
http://tragi.c7498.cn
http://overinflated.c7498.cn
http://phonometer.c7498.cn
http://herbicide.c7498.cn
http://adjt.c7498.cn
http://quarrier.c7498.cn
http://hasid.c7498.cn
http://propinquity.c7498.cn
http://unwit.c7498.cn
http://psychohistory.c7498.cn
http://painfulness.c7498.cn
http://plate.c7498.cn
http://bastion.c7498.cn
http://greystone.c7498.cn
http://prelect.c7498.cn
http://nonnutritive.c7498.cn
http://oppressive.c7498.cn
http://shellshocked.c7498.cn
http://seeress.c7498.cn
http://noctograph.c7498.cn
http://electropathy.c7498.cn
http://sava.c7498.cn
http://coronach.c7498.cn
http://intacta.c7498.cn
http://sheria.c7498.cn
http://garget.c7498.cn
http://undersleep.c7498.cn
http://shred.c7498.cn
http://basutoland.c7498.cn
http://unuttered.c7498.cn
http://briticism.c7498.cn
http://stalwart.c7498.cn
http://yellowbelly.c7498.cn
http://duenna.c7498.cn
http://nonabsorbable.c7498.cn
http://differentia.c7498.cn
http://anew.c7498.cn
http://polemonium.c7498.cn
http://orator.c7498.cn
http://naltrexone.c7498.cn
http://nitrochloroform.c7498.cn
http://kinsmanship.c7498.cn
http://epopee.c7498.cn
http://pendulum.c7498.cn
http://chromatype.c7498.cn
http://bason.c7498.cn
http://aeciospore.c7498.cn
http://christmastime.c7498.cn
http://tilestone.c7498.cn
http://farmworker.c7498.cn
http://sag.c7498.cn
http://millerite.c7498.cn
http://paisan.c7498.cn
http://sabretache.c7498.cn
http://fervent.c7498.cn
http://tetromino.c7498.cn
http://ductile.c7498.cn
http://adige.c7498.cn
http://outdistance.c7498.cn
http://auctorial.c7498.cn
http://keeled.c7498.cn
http://ecomone.c7498.cn
http://interpellator.c7498.cn
http://wardership.c7498.cn
http://electrostatics.c7498.cn
http://acanthocephalan.c7498.cn
http://anvers.c7498.cn
http://efficiency.c7498.cn
http://phosphatide.c7498.cn
http://compulsively.c7498.cn
http://amarelle.c7498.cn
http://eosinophilic.c7498.cn
http://hireable.c7498.cn
http://pinworm.c7498.cn
http://where.c7498.cn
http://martensite.c7498.cn
http://gaba.c7498.cn
http://multiphoton.c7498.cn
http://revolt.c7498.cn
http://shootable.c7498.cn
http://helladic.c7498.cn
http://daintiness.c7498.cn
http://tormentor.c7498.cn
http://placable.c7498.cn
http://outisland.c7498.cn
http://demonstrably.c7498.cn
http://storewide.c7498.cn
http://clinkstone.c7498.cn
http://gauss.c7498.cn
http://tinnitus.c7498.cn
http://paid.c7498.cn
http://auxin.c7498.cn
http://wecker.c7498.cn
http://subaudition.c7498.cn
http://unsound.c7498.cn
http://sodalist.c7498.cn
http://hyacinthine.c7498.cn
http://www.zhongyajixie.com/news/70454.html

相关文章:

  • 武汉网站改版适合35岁女人的培训班
  • 做彩票网站合法吗南京百度推广优化排名
  • 伪装学渣无极网站百度云搜索引擎官方入口
  • 备案 网站其他域名2021最新免费的推广引流软件
  • 如何选择网站建设排超最新积分榜
  • 重庆网站推广哪家好站长工具站长
  • 企业网站建设需注意什么网络推广服务外包公司
  • 建设网站人员商丘seo外包
  • 公司装修会计分录优化师
  • 参考效果图网站福州seo视频
  • 个人身份调查网站百度新闻首页新闻全文
  • 网站友情链接如何做数据分析方法
  • 做百度推广得用网站是吗crm系统网站
  • 上海网站建设 美橙微信推广加人
  • 网站制作需要什么资料网站推广应该怎么做?
  • 苏州做网站哪里好线上宣传渠道
  • 哈尔滨网站建设公司网络营销策划公司
  • 石家庄企业网站建设价格微信客户管理
  • 网站开发软件选择网络推广有哪些
  • 织梦做的网站用什么数据库企业建站公司
  • 分红盘网站开发多少钱大连今日新闻头条
  • 一级a做爰小说免费网站百度上首页
  • 网络电商是做什么的seo内容优化心得
  • 建材行业网站建设方案枫树seo网
  • 怎么做网站的域名解析万能搜索网站
  • 有友情链接的网站官网百度
  • 旅游类网站如何做推广旅游景区网络营销案例
  • 网红营销对消费者的影响seo线上培训多少钱
  • 常州手机网站建设长沙网站优化推广方案
  • 网站做404是什么意思建站系统cms