You need to know before you do the automated tests.

Source: Internet
Author: User
Tags writing test scripts selenium grid

What is automated testing?

Testing for several years, the real learning and practice of automated testing for a year, self-feeling this year to harvest a lot. Always wanted to write an article to share some experience in automated test practice. Finally decided to take some time to do the thing.

First of all, the concept of automated testing, in a broad sense, automation, including all through the tool (program) to replace or auxiliary manual testing behavior can be seen as automation, including performance testing tools (LoadRunner, JMeter), or a program written by oneself, Used to generate 1 to 100 test data. In a narrow sense, a tool that records or writes a script simulates the process of manual testing by replaying or running a script to execute a test case, instead of manually validating the system's functionality.

Of course, we are more generally aware of the "automated testing" as "automated testing based on the product or project UI layer."

Automated, tiered testing

This concept has a relatively high degree of exposure, and traditional automated testing is more focused on automated testing of the product UI layer, while layered automated testing advocates that the different stages (levels) of the product require automated testing.

Believe that the test students on the above pyramid is not unfamiliar, this is not the product development at different stages of the corresponding test! We need the standard to do unit testing also need the corresponding unit test framework, such as Java JUnit, testng,c# NUnit, Python unittest, pytest, and so on, almost all the mainstream language, will have its corresponding unit test framework.

Integration, interface testing is not easy to understand for many novice testers, unit testing is concerned with the implementation logic of the code, such as an if branch or a for loop implementation, then the integration, interface testing is concerned about a function, the class (method) provides a reliable interface. For example, I define an Add () function to calculate the result of two parameters and return it, then I need to call Add () and pass the parameter, and compare the return value to add two parameters. Of course, the interface test can also be passed in the form of a URL. For example, we send a request to the server by a Get method, and the content we send is passed to the server side as part of the URL. However, for example, WEB Service technology provides a public interface that needs to be tested by tools such as SOAPUI.

The UI layer of automated testing, this should be more familiar with, most of the testers are most of the work of the UI layer to test the functionality. For example, we repeatedly test the functionality of a form submission, results query, and so on, we can simulate these operations with the appropriate automated testing tools to free up repetitive labor. There are many automated testing tools in the UI layer, the Qtp,robot Framework, Watir, selenium, etc. are the mainstream.

Why do you want to draw a pyramid, not a rectangle or an inverted triangle? This is to indicate the proportion of automated tests that have been put into operation at different stages. If a product has never done unit testing and interface testing, it is unscientific to do only the UI layer of automated testing, which makes it difficult to guarantee the quality of the product in essence. If you attempt to achieve a comprehensive UI layer of automated testing, it is a costly move, put a lot of manpower time, the final gains may be much lower than the cost of the payment. Because the higher the upper, the higher the maintenance cost. The elements of the UI layer, in particular, are often changed. Therefore, we should put more automated tests in the unit testing and interface testing phase.

Now that the UI layer's automated tests are so costly, we only do unit tests and interface tests. No! Because no matter what kind of product, ultimately presented to the user is the UI layer. Therefore, testers should be more focused on the UI layer. So it is because testers put a lot of effort into the UI layer, so it is necessary to help us in an automated way to "partially liberate" repetitive labor.

In automated testing, the most feared change, because the direct result of the change is to lead to the failure of the test case, then need to maintain the automation script, how to control the failure, reducing maintenance costs is crucial to the success of the customization. Conversely, an automated test case that will always run successfully is of no value.

As for the scale of the three Tests in the pyramid, they are divided according to the actual project requirements. In the "Google test" book, for Google products, 70% of the investment is unit testing, 20% for integration, interface testing, 10% for the UI layer of automated testing.

Why should I do automated testing?

According to the 51testing "China Software Testing Practitioners Survey Report", manual testing accounted for 89%, relative development, the threshold of testing, wages generally lower, the required range of knowledge although a certain breadth, but lack of depth. This is the general state of the test.

Because of the low threshold of hand-work test, a large number of graduates, even non-professionals poured into the industry. This has increased the industry's fierce competition. There is a strong sense of crisis for those who have been working on manual tests for several years. Because the technical content of the work is not high, the salary increase encountered bottleneck, on the other hand by the new entrants threat, the same job companies spend 5 K recruit people can do, then will not spend 8K.

Well, the question shouldn't be on the topic of technology, but he's really a problem that most testers have to face. So, from the tester's own development, I really need to use automation technology to increase their competitiveness. Of course, to achieve a certain number of years of testing staff will choose to transfer management or other positions, this is another topic.

From the development of testing industry, domestic products because of product characteristics, world-class products are not many, relatively low technical content, the quality requirements of relatively low requirements, outsourcing foreign projects, testing manpower cost is cheap, so need a large number of manual testing staff.

So, in the not-too-distant future, I think the demand for pure hand testers is diminishing, and companies need to test for higher technical capabilities. Quality needs to be tested and test behavior never disappears, but it is possible for pure manual testers to disappear.

Well, you can say that testing the industry, I am purely alarmist. No matter what the future is, we need to improve our skills, right?

What projects are suitable for automated testing?

If you have decided to learn automated testing, how to learn is the next problem to be faced? This problem is analyzed by the test product as the starting point, if you learn the technology can not be applied (validation), will make your learning process difficult.

First consider whether the product is suitable for automated testing. The common consensus of this approach is to weigh in three ways.

Software Requirements Change infrequently

The stability of the test script determines the maintenance cost of the automated test. If the software requirements change too frequently, testers need to update the test cases and related test scripts according to the needs of the changes, and the maintenance of the script itself is a process of code development, need to modify, debug, and, if necessary, modify the framework of the automated test, if the cost is not lower than the test cost of using its savings , then automated testing is a failure.

Some of the modules in the project are relatively stable, and some of the modules require a lot of variability. We can automatically test the relatively stable modules, while the larger changes are still tested by hand.

Longer project Life

Because of the determination of automation test requirements, the design of the automated test framework, the writing and debugging of test scripts, it takes quite a long time to complete. The process itself is a test software development process that takes a long time to complete. If the project's cycle is short and there is not enough time to support such a process, then automated testing becomes a joke.

Automated test scripts can be reused

The re-use of automated test scripts should be considered in three ways, on the one hand, whether there are significant differences between the projects tested (such as the difference between the C/s system and the/b system), whether the test tools selected adapt to this difference, and finally, whether the tester has the ability to develop an automated testing framework that adapts to this difference.

What tools are selected for automated testing

If you have confirmed that the XX project is suitable for automated testing, then the next thing you need to do is to choose a test tool.

First make sure that the product you are testing is a desktop program (c/s) or a Web application (b/s).

The tools of the desktop program are: QTP, Autorunner

Tools for Web applications are: QTP, Autorunner, Robot Framework, Watir, selenium

Due to the advantages of B/s architecture, a large number of C/S architectures have been converted to B/s structure earlier years ago. Thus, the development of web development and testing technology is also promoted. If the product being tested is C/s architecture, then recommend QTP, QTP in the UI Automation testing area accounted for half of the trial rate. So, enough to illustrate the QTP in the field of automation powerful, ease of use and so on. Learning the tools of the mainstream can also help you get more opportunities. The books on QTP are also very rich in the market. Of course, to learn QTP, you have to master the VBS scripting language.

If the product being tested is b/s structure, then recommended selenium, why not QTP or other tools? Because selenium to B/s application support is very good, more important, it supports the development of multiple languages, the real trial selenium, you have to master not only a tool, you also need to learn a language. Why should I choose selenium? Also need to learn a language, which undoubtedly increases my study cost. Increase costs while also increasing your competitiveness, and, in this process you are not just learning an automated tool, you can use the language you learn to do more things.

All right! If you decide to try selenium, you face a new problem, choose a language. Selenium is supported by Java, Python, Ruby, PHP, C #, JavaScript.

In terms of language accessibility, Ruby is preferred, python

From the breadth of language application, the preferred Java, C #, PHP,

In terms of language-related testing techniques (and materials): Ruby, Python, Java

Or you can consider what language the entire technical team will mainstream, and then choose the appropriate language.

Selenium Pre-use notice

Ok! After the process, I believe you must make the appropriate choice, if you choose the Selenium tool, then read down.

First choice you need to take a two months time to learn a language before you start selenium, which is based on students who don't have a language base. I recommend Ruby, Python, and any language in Java to learn.

Of course, if you have a good language base to skip this link, or your rich Java programming capabilities, then learning Python may take only a few days or less.

If you've got the basics of a language, then you need to know selenium, selenium is not just a tool, he's a collection of tools, and he has 1.0 and 2.0 points, and of course 3.0 has arrived.

Selenium is not a simple tool, but consists of several tools, each with its own features and application scenarios.

Selenium IDE

The selenium IDE is a plugin embedded in the Firefox browser that enables simple browser operation recording and playback functions. So what's the use of it?

Quickly create a bug replay script that, during the tester's test, discovers bugs that can be recorded by the IDE to reproduce the steps to help developers reproduce the bug more easily.

The IDE's recorded scripts can be translated into multiple languages, helping us to develop scripts quickly, which are described in detail later in this function.

Selenium Grid

The Selenium grid is an automated test aid that allows the grid to speed up Web-app functional testing by leveraging existing computer infrastructures. Grid makes it easy to run multiple test cases concurrently on multiple machines and in heterogeneous environments. Its features are:

· Parallel execution

· Run with a single host unified control case in different environments and different browsers.

· Flexibility to add change testing machine

Selenium RC

Selenium RC is the Selenium family's core tool, selenium RC supports a variety of different languages to write automated test scripts, through the Selenium RC server as a proxy server to access the application to achieve the purpose of testing.

Selenium RC uses the sub-Client libraries and selenium server,client libraries libraries primarily for writing test scripts to control the library of the selenium Server.

Selenium server is responsible for controlling browser behavior, in general, the Selenium server mainly consists of 3 parts: Launcher, Http Proxy, Core. Where selenium core is embedded in the browser page by Selenium server. In fact, selenium core is a collection of JS functions, that is, through these JS functions, we can implement the browser operation with the program. Launcher is used to launch the browser, load the Selnium core into the browser page, and set the browser's proxy to selenium Server's HTTP proxy.

Selenium 2.0

Clarified the family relationship of Selenium 1.0, Selenium 2.0 was to add webdriver to the family; The simple formula is expressed as:

Selenium 2.0 = Selenium 1.0 + webdriver

It should be emphasized that the main thrust in Selenium 2.0 is Webdriver, Webdriver is selenium RC alternatives, because selenium for backwards compatibility, so selenium RC did not completely abandon, If you use selenium to develop a new automated test project, the strong column recommends using Webdriver. So what is the difference between selenium RC and webdriver?

Selenium RC runs the JavaScript app in the browser, using the browser's built-in JavaScript translator to translate and execute the Selenese command (Selenese is a collection of selenium commands).

Webdriver directly controls the browser via native browser support or browser extensions. Webdriver is developed for each browser, replacing JavaScript embedded in the Web App under test. Tight integration with the browser enables the creation of more advanced tests, avoiding the limitations caused by the JavaScript security model. In addition to support from the browser vendor, Webdriver also simulates user input using an operating system-level call.

If it is a new project to learn directly webdriver is OK, RC is outdated technology.

Selenium Learning Route

Configure your test environment, really for the language you are learning, to configure your corresponding selenium test environment. Selenium is like the definition of semantic---"hello", if you are using Chinese, to say hello to the table, your writing is "Hello", if you use English, you are written "Hello." Therefore, there are different semantics in different languages (syntax).

Then you need to be familiar with the Webdriver API, the API is a method defined by selenium, used to locate, manipulate the various elements on the page.

To learn the positioning of the element first, selenium provides the ID, name, class name, tag name, link text, Partial link text, XPath, CSS, and other positioning methods. The powerful syntax for XPath and CSS is slightly more complex, and you may need to know more about the front-end knowledge in the meantime. XML, JavaScript, and so on.

The purpose of positioning elements is to manipulate elements, then learn the various elements have operation, input box, drop-down box, button click, file Upload, download, pagination, dialog box, warning box ... Wait a minute.

After a period of learning, you can easily simulate manual testing to manipulate the various elements on the page. Then all you need to do is to organize these "use cases" and run them together.

So what you need to do is learn and use the Unit test framework, which itself solves the organization and operation of use cases.

After you have written some "test Cases", you will find that there are a number of repeated actions in the use case, can you write to a separate file, and call these actions when needed? Of course, using your programming skills to achieve this will be very simple. Then you find that there are some data in each use case, and the same is true, but if you change it, you can write it in a separate file to read it.

Then you come across new questions, my scripts (use cases) are flowing, and how do I know if a use case fails or succeeds? Then you need to add some validation and assertions to the script.

Then you have more ideas, the unit Test framework log is too simple, can generate a beautiful test report. Can I run this script on a regular basis? Can I send the test results of every run script directly to my mailbox. Can......

To solve these problems, you have to learn more about programming techniques, and then your "test structure" will become more powerful and more flexible. has produced a certain universality and portability. A model-like automated testing framework was born.

If, one day, you no longer do the UI Automation test, you will find that you do a unit test or interface testing is basically no difficulty. Develop a test tool and so on, thank selenium! By the way, thank me!

Original link: http://www.cnblogs.com/fnng/p/3653793.html

(turn) You need to know before you do the automated tests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.