在云端西科大
Any developer familiar with the testing process will agree that it is pure evil. In a traditional set up testing requires setting up new environments at every turn which is being used sporadically at best. Not just a major chunk of your resources are lying idle for the most part, it also consumes a lot of time. For most of us testing is a non-critical business activity. But it is absolutely required, unless you want to meet your clients red faced.
任何熟悉测试过程的开发人员都会同意这是纯粹的邪恶。 在传统的设置中,测试需要在每个转弯处都设置新的环境,而该环境最多只能偶尔使用。 不仅大部分资源大部分都处于闲置状态,而且还浪费大量时间。 对于我们大多数人而言,测试是一项非关键的业务活动。 但这是绝对必要的,除非您想与客户见面。
Today the software development world has entered into the Cloud bandwagon, and everything is treated as a service. Sadly these benefits have seldom passed on to the testing side of the world. Well, not anymore. In this article I am going to show you how to set up your testing infrastructure in the Cloud using SauceLabs.
今天,软件开发界已经进入了云计算潮流,一切都被视为一种服务。 遗憾的是,这些好处很少传递到世界的测试方面。 好吧,不再了。 在本文中,我将向您展示如何使用SauceLabs在云中设置测试基础结构 。
Let us assume that you are building the next Amazon. You have hired a few awesome devs and your Before going mainstream, you might want to check how it behaves in different Operating systems, browsers, and resolutions. We also need to check how many parallel transactions your application is able to manage before it turns into the next IRCTC and drown. Obviously you will need some sort of infrastructure to back your team up. This is called as Testing Infrastructure.
让我们假设您正在构建下一个亚马逊。 您已经雇用了一些很棒的开发人员,并且在进入主流之前,您可能需要检查它在不同的操作系统,浏览器和分辨率下的行为。 我们还需要检查您的应用程序在变为下一个IRCTC并淹死之前能够管理多少个并行事务。 显然,您将需要某种基础架构来支持您的团队。 这称为测试基础结构。
Normally you will need to procure multiple systems depending upon your needs and configure each separately with the operating conditions of your choice. For load testing you will even need to set up a even more powerful, expensive system that effectively mimics your main server. Obviously this is going to cost, which is not feasible for a small organization.
通常,您将需要根据需要采购多个系统,并根据您选择的操作条件分别进行配置。 对于负载测试,您甚至需要设置一个功能更强大,价格昂贵的系统,以有效地模拟您的主服务器。 显然,这要花钱,这对于小型组织是不可行的。
Another problem is testing is not a full time task. It is only required when there is some change either in production, or the operating conditions. Other times your capital just sits idle in an air-conditioned room. The costs spirals up, and even before you realize you will be out of money to focus on other important tasks.
另一个问题是测试不是一项全职任务。 仅当生产或操作条件发生某些变化时才需要。 其他时候,您的资金只是闲置在空调房中。 成本上升,甚至在您意识到之前,您就没有钱去专注于其他重要任务。
When Cloud computing came into existence a lot of discussions circled around moving your testing infrastructure to the Cloud. The idea is to attain efficiency by decoupling your testing team from testing infrastructure. When you set up your testing infra in the Cloud, it does two things- it eliminates the need for an upfront Cap-Ex, and it allows you the flexibility to scale up/ scale down your operations on demand, there by efficiently utilizing your resources. It also effectively removes the headache of having to configure each system individually. Unfortunately it is not all roses either. There are many doubts creeping over data integrity and security in the Cloud, which could easily retract anyone from making the move.
云计算应运而生之后,围绕将您的测试基础架构迁移到云上进行了许多讨论。 这个想法是通过使您的测试团队与测试基础架构脱钩来实现效率的。 当您在云中设置测试基础设施时,它有两件事-消除了对前期Cap-Ex的需求,它使您可以灵活地按需扩展/按需缩减操作,从而有效利用资源。 它还有效地消除了必须分别配置每个系统的麻烦。 不幸的是,它也不是所有的玫瑰。 云中的数据完整性和安全性令人担忧,这很容易使任何人退缩。
SauceLabs is a cross-browser automation tool built on top of the famous Selenium Web-driver For those of us who do not know what Selenium is, “It is a technology that allows programmers to send commands to web browsers to make them perform tasks as though they were being used by a human. In this sense it is like a robot for web browsing.”, to quote their website. Essentially Selenium gives you the freedom to test your pages across browsers automatically, through test scripts. A Selenium server (locally installed) then instructs your browsers (with Selenium extensions enabled) to test your app. However it is a pain to install and manage the complete Selenium suite, especially if you are mooting for cross browser support. You will also have to face the brunt of hardware failures, and maintenance nightmares too.
SauceLabs是跨浏览器自动化工具,建立在著名的Selenium Web驱动程序的基础上。对于那些不知道Selenium是什么的我们来说,“这项技术允许程序员将命令发送到Web浏览器,以使他们执行任务。尽管它们被人类使用。 从这个意义上讲,它就像是一个用于网络浏览的机器人。”,引用他们的网站。 本质上,Selenium使您可以自由地通过测试脚本跨浏览器自动测试页面。 然后,Selenium服务器(本地安装)将指示您的浏览器(启用Selenium扩展)测试您的应用程序。 但是,安装和管理完整的Selenium套件非常麻烦,尤其是当您需要跨浏览器支持时。 您还必须面对硬件故障首当其冲的麻烦,并且还要面对维护方面的噩梦。
SauceLabs was developed by the same guys behind Selenium, as a solution to this problem. SauceLabs takes care of setting up the testing environment, only this time the setup resides in their Cloud servers. Then we can connect to those machines virtually from anywhere using any browser. Think of SauceLabs as a container having your testing environment, which you can access over Internet. We are now free of all the configuration related hoopla and we can focus on what really matters. Of course as with any Cloud setup you have the flexibility to fire up additional instances on demand, and even run parallel tests.
SauceLabs由Selenium背后的同一个人开发,以解决此问题。 SauceLabs负责设置测试环境,仅此一次设置驻留在其云服务器中。 然后,我们可以使用任何浏览器,随时随地连接到这些计算机。 将SauceLabs视为具有测试环境的容器,您可以通过Internet访问它。 现在,我们摆脱了与配置相关的所有hoopla,我们可以专注于真正重要的事情。 当然,与任何Cloud设置一样,您可以灵活地按需启动其他实例,甚至运行并行测试。
Once you sign up for a SauceLabs account, you get 200 free testing minutes, after which you’ll have to pay a small fee to continue using the service. Once you’re in the admin dashboard you can setup your test environment just by clicking the little pointer icon.
注册SauceLabs帐户后,您将获得200分钟的免费测试时间,在此之后,您将需要支付少量费用才能继续使用该服务。 进入管理控制台后,只需单击小指针图标即可设置测试环境。
Once SauceLabs is done configuring your machine it lets you connect to your web-app for further testing. One interesting thing to note is all the browsers come with developer tools pre-installed to help you in debugging the issues on the fly. You can navigate through your app and verify it for both functional and non functional issues. SauceLabs allows you to raise bugs directly from the tool immediately. It automatically uploads the screenshot of the page where the bug is and a video showing how to reach the page. This should remove any ambiguity, if any during fixing the issue. It also generates a Selenium style log which should come in handy later on. The dashboard gives also presents you with a colorful, comprehensive overview of what is happening with your testing scenarios to keep your managers happy.
SauceLabs完成配置计算机后,就可以连接到Web应用程序进行进一步的测试。 需要注意的一件事是,所有浏览器都预装有开发人员工具,可帮助您即时调试问题。 您可以浏览您的应用程序,并针对功能性和非功能性问题进行验证。 SauceLabs允许您立即直接从工具中引发错误。 它会自动上传该错误所在页面的屏幕截图,以及一个视频,显示如何访问该页面。 如果解决问题,这应该消除任何歧义。 它还会生成一个Selenium样式的日志,稍后应派上用场。 仪表板还为您提供了丰富多彩的,全面的测试场景概述,以使您的经理满意。
Manual testing is redundant, time consuming, and boring. Selenium offers a powerful test suite to automate your testing. The best part is you need not circumscribe yourself to the language in which the application is developed. In fact you can write your test scripts with any programming language in which you’re comfortable with. For the purpose of this tutorial we’ll be using Ruby. This tutorial assumes that you’ve a working copy of Ruby installed in your machine.
手动测试是多余,费时且无聊的。 Selenium提供了功能强大的测试套件,可以自动执行测试。 最好的部分是您不必限制自己使用应用程序开发所用的语言。 实际上,您可以使用任何您喜欢的编程语言编写测试脚本。 就本教程而言,我们将使用Ruby。 本教程假定您已经在机器中安装了Ruby的工作副本。
Lets first get the dependencies out of our way with
首先让我们摆脱依赖
gem install selenium-webdriver
We will now write a basic snippet to check if search works in CloudSpring.com. Have your access key handy.
现在,我们将编写一个基本代码段,以检查搜索在CloudSpring.com中是否有效。 随身携带您的访问密钥。
require 'rubygems'
require 'selenium-webdriver'</code>
caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps[:name] = "Learning SauceLabs- CloudSpring"
driver=Selenium::WebDriver.for(
:remote,
:url => "http://saucelabs_username:saucelabs_accesskey@ondemand.saucelabs.com:80/wd/hub",
:desired_capabilities => caps)
driver.navigate.to "http://CloudSpring.com"
element = driver.find_element(:xpath, "(//input[@name='s'])")
element.send_keys "A newbie's guide to Amazon EC2"
element.submit
puts "Yay! Search works."
puts driver.title
driver.quit
Save this file as test.rb and execute it by
将此文件另存为test.rb并执行
ruby test.rb
Your result should resemble this
您的结果应类似于此
Head over to the dashboard, and you will find the test log. It lists the steps followed and even shows a video of how the script executed.
转到仪表板,您将找到测试日志。 它列出了遵循的步骤,甚至显示了有关脚本执行方式的视频。
The code we’ve written is self-explanatory (and utterly useless, mind you) but for brevity sake let us take a little detour.
我们编写的代码是不言自明的(请注意,这完全没有用),但是为了简洁起见,让我们绕道走一下。
caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps[:name] = "Learning SauceLabs- CloudSpring"
driver=Selenium::WebDriver.for(
:remote,
:url => "http://saucelabs_username:sauce_labs_access_key@ondemand.saucelabs.com:80/wd/hub",
:desired_capabilities => caps)
Capability is what defines the scope of your script. This is where you define you executing environment like operating system, browser, and even the version. SauceLabs sets up your VM based on this. WebDriver separates where the tests are running from where the TI, or in this case the browser is. It connects to your VM and starts the execution on the environment you’ve set. This where SauceLabs makes our life a lot easier. We just specify which browser to work on on the script and it takes care of the installation and stuff. We don’t have to lift another finger unnecessarily.
能力是定义脚本范围的因素。 在这里,您可以定义执行环境,例如操作系统,浏览器,甚至版本。 SauceLabs基于此设置您的VM。 WebDriver将测试的运行位置与TI的位置(或本例中的浏览器)分开。 它连接到您的VM并在您设置的环境上开始执行。 SauceLabs在这里使我们的生活更加轻松。 我们只需要指定要在脚本上使用的浏览器,它就会处理安装和工作。 我们不必不必要地举起另一只手指。
driver.navigate.to "http://CloudSpring.com"
Now we’re instruct the browser to navigate to thew URL where you want to perform your testing. Your driver object will now have the entire page.
现在,我们指示浏览器导航到您要执行测试的URL。 现在,您的驱动程序对象将具有整个页面。
element = driver.find_element(:xpath, "(//input[@name='s'])")
element.send_keys "A newbie's guide to Amazon EC2"
element.submit
The find_element() traverses the DOM based on the parameters we pass. I’m asking the browser to look for an input field with the name ‘s’ and pass the search string to it.
find_element()根据我们传递的参数遍历DOM。 我要浏览器查找名称为“ s”的输入字段,并将搜索字符串传递给它。
Author’s Note: We’re essentially writing the same old Selenium scripts, and using SauceLabs as a platform to execute it. If you already have written any selenium scripts they should work the same way. For those of us who’re new to Selenium or can’t quite understand how WebDriver works, download the Selenium IDE extension for Firefox and you can create your test scripts directly from the browser itself.
作者注:我们实际上是在编写相同的旧Selenium脚本,并使用SauceLabs作为执行该脚本的平台。 如果您已经编写了任何Selenium脚本,它们应该以相同的方式工作。 对于那些不熟悉Selenium或不太了解WebDriver如何工作的人,请下载Firefox的Selenium IDE扩展,您可以直接从浏览器本身创建测试脚本。
In real time scenarios we’ll be using verify..() or assert..() methods to validate the scripts. But since this article is focused on how to move your test scripts to the cloud, I’m drawing the line here.
在实时场景中,我们将使用verify ..()或assert ..()方法来验证脚本。 但是由于本文的重点是如何将您的测试脚本迁移到云中,因此我在这里划清界限。
Many people have steered clear of Cloud just because they feel it is insecure. It is just that- a myth, but that is a discussion for another day. To dispel any such doubts that you might have the team at SauceLabs employs a new approach- Security through purity. They assure you that your cloud VM once used is completely destroyed with all the data and not reallocated to anyone else. Have a sensitive data pool to be tested. Fret’ not. They offer a secure service called SauceConnect to prevent any data leakage. With the initial barrier out of our way, I strongly encourage you to take advantage of this wonderful technology.
许多人只是因为觉得云不安全而避开了云。 只是一个神话,但这是另一天的讨论。 为了消除任何可能使您在SauceLabs的团队中遇到的疑问,我们采用了一种新方法-通过纯净实现安全。 他们向您保证,一旦使用,您的云VM将被所有数据完全破坏,并且不会重新分配给其他任何人。 有一个要测试的敏感数据池。 不用。 他们提供了称为SauceConnect的安全服务,以防止任何数据泄漏。 克服了最初的障碍,我强烈建议您利用这项出色的技术。
Testing in the cloud, especially for startups, offers a huge array of things. You don’t have to pay a penny upfront and you pay for what you use rather than wasting resources. And with SauceLabs all your test scripts are automatically logged, eliminating the need for manual intervention. Of course we’ve just scratched the surface today and there is a long way to go before your application can be completely tested on the cloud. We hope to rectify that in the future articles.
在云中进行测试(尤其是针对初创企业)可提供大量的功能。 您不必先付一分钱,您只需为使用的东西付费,而不是浪费资源。 借助SauceLabs,您的所有测试脚本都将自动记录下来,从而无需手动干预。 当然,今天我们才刚刚起步,要在云上对您的应用程序进行完全测试还有很长的路要走。 我们希望在以后的文章中对此进行纠正。
What would you like us to cover here in the future? Feel free to join us in the discussion and let us know about your thoughts. Thanks for reading, and stay tuned.
您希望我们将来在这里介绍什么? 欢迎加入我们的讨论,并让我们知道您的想法。 感谢您的阅读,敬请期待。
翻译自: https://www.sitepoint.com/testing-in-the-cloud-using-saucelabs/
在云端西科大