Go语言中的自动化 – 如何使用类似Selenium的浏览器自动化?

huangapple go评论83阅读模式
英文:

Automation in Go Lang - How to use browser automation like Selenium?

问题

我是你的中文翻译助手,以下是你要翻译的内容:

我对Golang还不熟悉,我正在寻找一种能够自动化网页应用程序中的注册和登录过程的工具。请推荐一个像Selenium这样的好工具,并告诉我如何在Go语言中实现它。

我想使用Golang自动完成以下过程:

  1. 启动一个浏览器。目前,我正在使用https://github.com/skratchdot/open-golang。
  2. 在注册页面上自动填写表单并自动提交。
  3. 对已注册用户进行登录检查。需要自动完成所有操作以适应更多用户。
英文:

I am new to Golang. And I am looking for automating signup, login processes in a web app. Please suggest a good tool like Selenium and how can I implement it in the go language.

I want to do the following process automatically using Golang:

  1. Start a browser. Currently, I'm using https://github.com/skratchdot/open-golang
  2. Auto entry on the signup page and auto-submit a form.
  3. Login check for the registered user. Everything needs to be done automatically for more users.

答案1

得分: 3

如果你要使用GO进行Web自动化测试,Selenium是一个不错的选择。不过,它只是一个允许你与浏览器进行交互的库而已。所以你需要开发自己的框架或者重用别人已经实现的框架。

我的建议是考虑使用Agouti,因为它支持Ginkgo的BDD和xUnit Gomega。从架构的角度来看,其他方面基本上都是一样的。你可以像设计其他语言绑定一样设计它。在浏览器自动化框架中,有一些常见的模式一次又一次地出现,比如:

  • PageObjects:对你的Web应用程序的UI进行简单的抽象。
  • LoadableComponent:将PageObjects建模为组件。
  • BotStyleTests:基于命令的方法。

构建测试框架的另一个好资源是xunitpatterns指南。它提供了模式、问题和重构策略的很好的内容概述。还可以参考这个test frameworks tutorial。它将帮助你选择最合适的解决方案。

我猜你可能需要一些CI服务器支持,因为

> 所有事情都需要自动化处理,以适应更多的用户。

这里有一篇很好的文章,介绍了如何使用TravisCI实现这一点。

英文:

If you are going to use GO for web automation testing - Selenium is a good option. Still it's nothing more than a library that allows you to interact with browsers. So you are going to need to develop your own framework or reuse someone already implemented.

My advice is to consider Agouti, since it supports Ginkgo BDD and xUnit Gomega. Everything else is pretty much the same from architectural perspective. You can design it like any other language binding. There are common patterns that appear over and over again in browser automation frameworks, like

  • PageObjects: A simple abstraction of the UI of your web app.
  • LoadableComponent: Modeling PageObjects as components.
  • BotStyleTests: command-based approach

Another good resource for building your Test framework is the xunitpatterns guide. It gives a great content overview of the patterns, smells and refactoring strategies you can use. Also look at this test frameworks tutorial. It'll help you choose the most proper solution for your case.

My guess is that you are going to need some CI server support for

> everything needs to be done auto for more users.

Here is a good article how-to achieve this with TravisCI.

答案2

得分: 3

你还可以使用Playwright for Go,它是Playwright项目的一个封装。Playwright提供了一个统一的API,用于自动化Chromium、Firefox和WebKit,可以自动化浏览器操作,该项目由Microsoft创建。使用它,你可以与网站进行交互,录制视频,截取屏幕截图,并模拟其他特定于浏览器的行为。

英文:

You can also use Playwright for Go, which is a wrapper for the Playwright project. Playwright provides a single API to automate Chromium, Firefox, and WebKit to automate browsers which was created by Microsoft. With it you interact with the sites, record videos, make screenshots, and emulate other browser specific behaviour.

答案3

得分: 2

你可以使用Selenium for Golang

英文:

update:
you can use Selenium for Golang

huangapple
  • 本文由 发表于 2016年1月11日 13:48:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/34714948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定