Speaking of automated testing, I think everyone will have a question. Do you want to perform automated testing? Whether the benefits brought by automated testing will exceed the cost invested during the construction process, let alone me. Even the experts are hard to answer. The original intention of automated testing is beautiful, test engineers often spend a lot of money and effort in the implementation process, and eventually end with failure. There are many reasons for failure. I will summarize several items:
1. relying too much on test tools, overestimated the power of the tools, and eventually ended with disappointment.
2. In case of project emergency, the whole link is interrupted to avoid unnecessary links and perform manual tests.
3. Developers and testers cannot interact well. If there is a firewall between the two roles, do not perform automated testing. Manual testing won't do well. Testers can think of R & D as their own girlfriends and try to cultivate mutual feelings.
4. The low mood caused by the underestimation of the strength of automated testing personnel. This problem will occur in all positions. Of course, it depends on the importance of the leadership.
5. If there are not enough resources, the company will not be willing to invest in resources, or you may just need to waste your time.
6. Too high expectations and too low returns.
Currently, few companies in China say they can turn to automated testing. They are very popular when looking at familiar foreign companies like Google and Microsoft. It is ridiculous that I have worked as a test Manager for several years in Microsoft's China testing department to come up with the Microsoft test system best practices course. I am not saying that they are not good, but I hope we can pay attention to them, you need to know that the "excellence" system is also built by those "professional teams" who have spent a lot of time and energy. So let's not talk about the benefits first, even for this beautiful original intention, we should also try it, even if it fails.
I also did tests for a few years, but I recently started to study automated testing. I have been more or less familiar with several common tools at work, such as silktest and selenium, I have heard of all the tests. I recently set up a testing framework for an existing project and compiled some test cases for some modules. The benefits are quite high, let's talk about these two tools first.
Silktest is a commercial tool that requires money to use, but it is easy to learn from existing platforms and frameworks. It can be based on Windows and UNIX platforms. IE, Firefox (partial) browser. It can be used for recording playback, object recognition, or manual programming, as well as data-driven, keyword-driven, and other testing frameworks. The language 4 test in silktest is actually a class C (also known as silk4j, written in Java), with relatively strong programming capability.
Selenium is free and requires similar IDE (such as Eclipse). It was originally developed by several cool people in thoughtworks and is now maintained by Google (people have switched over ). It can be based on Windows, UNIX, Mac, and other platforms. IE, Firefox and other browsers. The test team has insufficient funds and strong capabilities (in Java). Selenium is a good choice if it has high requirements on the test platform and Environment (ie, Firefox, Safari, etc.
Today, I will introduce how to build an automated testing framework through JUnit + selenium + coverlipse + ant. Before that, I will raise several questions, please read this article based on the following questionsArticle.
1. How to record the script?
2. How to convert to JUnit scripts?
3. How to generate JUnit logs?
4. How do I play back selenium and view playback logs?
5. How to viewCode?
I. Prepare the tool
Tools
Description
Download
JUnit
JUnit is a developmentSource codeJava testing framework for writing and running repeated tests.
Http://www.junit.org
Selenium
First, we will introduce two important components, selenium-ide, to record scripts. the abbreviation of selenium-RC selenium-remote control is to write test classes in specific languages.
Http://seleniumhq.org/download/
Coverlipse
Coverlipse this Eclipse plug-in can overwrite and visualize the code tested by JUnit.
Http://coverlipse.sourceforge.net/download.php
Ant
Ant is a tool similar to make and everyone is familiar with it. here we can use ant task to generate JUnit logs.
Http://ant.apache.org/bindownload.cgi
Ii. JUnit Installation
1. Eclipse itself comes with the JUnit. jar package. In general, you do not need to download the JUnit package.
2. Add the junit3 Library to the buildpath of the project.
3. Because JUnit logs are generated by ant, you must add JUnit. jar to ant_home.
Iii. Selenium Installation
1. Install seleniumide, open the Firefox browser, and go to tools> Add attachments to search for seleniumide.
2. After querying the corresponding IDE, click Install directly. After the installation is complete, restart Firefox. The following menu shows that the installation is successful.
3. Install selenium-RC and go to the http://www.openqa.org/selenium/ to download the selenium package. Decompress the package to the Directory D: \ autotesting \ selenium-server-standalone-2.0b1.jar with the command line.
4. Run the Java-jar selenium-server-standalone-2.0b1.jar to start selenium server. To separate the browser where the application runs from the browser of the selenium service at runtime, you can add-multiwindow to the end of the browser.
5. create a project in eclipse, add the elenium-server-1.0-beta-1 under the selenium-server.jar, selenium-Java-client-driver-1.0-beta-1 under the selenium-java-client-driver.jar In the build path of the project (these two are in the package that just unzipped) and eclipse \ plugins \ Org. junit_3.8.1 JUnit. jar.
6. Import the developed jar package into the project, and then you can integrate and use the corresponding API to compile your own test case.
Iv. coverlipse Installation
1. Install the SDK directly through eclipse. The steps are as follows:
• In eclipse, click Help-> Software Updates-> Find and install.
• In the dialog, select search for new features to install, then next.
• In the next step, add a new remote site. Name it "coverlipse Update site", the URL is "http://coverlipse.sf.net/update ".
• Press finish. Eclipse now searches for the coverlipse feature to install and shows that to you. 2. Configure coverlipse to get code override
3. Once you click Run, eclipse will run coverlipse and embed the tag in source code (7). The tag displays the code section with the relevant JUnit test.
4. Reports generated by coverlipse with embedded class tags
5. As you can see, using the coverlipse Eclipse plug-in can quickly determine code coverage. For example, this real-time data function helps you better test the code before it is checked into the CM system.
5. Install ant, which comes with eclipse. You only need to configure the environment variable ant_home.
6. Create a case
1. Create a project testselenium to install the following directory structure
2. Record the script. Open the Firefox browser and go to the selenium ide menu.
3. Enter the recording address and click the red button to start recording.
4. Convert the script into the JUnit code and copy it to the test class as the prototype of the test case code.
6. How to view logs:
L JUnit logs, the log records generated by these operations through the assertions written by JUnit and standard output.
L selenium logs: When the JUnit script is run, selenium-related scripts generate playback logs, such as the URL, standard input, and output of the interface.
Although there is no intersection between the two types of logs, You need to view them separately. However, in general, we only need to observe that the selenium log is enough, which is more suitable for the encoding phase than the JUnit log.
1. JUnit log, Just configure the script build-selenium.xml, as shown below
<Project name = "seleniumtest" default = "JUnit" basedir = ".">
<Property environment = "env"/>
<Condition Property = "IA. Home" value = "$ {env. ia_home}">
<Isset property = "env. ia_home"/>
</Condition>
<Property name = "Run. classpath" value = ".../class">
</Property>
<Property name = "Run. srcpath" value = ".../testselenium">
</Property>
<Property name = "test. xml" value = "../XML">
</Property>
<Property name = "test. Report" value = "../Report">
</Property>
<Property name = "Lib. dir" value = "../lib"/>
<Path id = "compile. Path">
<Fileset dir = "$ {Lib. dir}">
<Include name = "JUnit. Jar"/>
<Include name = "ant. Jar"/>
</Fileset>
</Path>
<Target name = "init">
<Delete dir = "$ {run. classpath}"/>
<Mkdir dir = "$ {run. classpath}"/>
<Delete dir = "$ {test. Report}"/>
<Mkdir dir = "$ {test. Report}"/>
<Delete dir = "$ {test. xml}"/>
<Mkdir dir = "$ {test. xml}"/>
</Target>
<Target name = "compile" depends = "init">
<Javac destdir = "$ {run. classpath}" srcdir = "$ {run. srcpath}"/>
</Target>
<Target name = "JUnit" depends = "compile">
<JUnit printsummary = "false">
<Classpath Path = "$ {run. classpath}">
<Path refID = "compile. Path"/>
</Classpath>
<Formatter type = "XML"/>
<Batchtest todir = "$ {test. xml}">
<Fileset dir = "$ {run. classpath}">
<Include name = "**/test *. Class"/>
<Include name = "**/* test. Class"/>
</Fileset>
</Batchtest>
</JUnit>
<Junitreport todir = "$ {test. xml}">
<Fileset dir = "$ {test. xml}">
<Include name = "test-*. xml"/>
</Fileset>
<Report format = "frames" todir = "$ {test. Report}"/>
</Junitreport>
</Target>
</Project>
2. After the ant script is run, the corresponding JUnit log can be generated.
1. Selenium log
When running the JUnit script, selenium-related scripts will generate playback logs, but the items recorded by default are too readable, so we use loggingselenium (http://loggingselenium.sourceforge.net/usage.html ), you can generate the result in the HTML format of the selenium command for each case.
4. Plugin:
Http://sourceforge.net/projects/loggingselenium/files/loggingselenium/Release%201.2/logging-selenium-1.2.jar/download
5. Installation Method: Just import the downloaded logging-selenium-1.2.jar to the project.
6. Write the following code:
@ Before
Public void setup (){
Final string resultpath = "absolute-path-to-where-your-result-will-be-written ";
Final string resulthtmlfilename = resultpath + file. Separator + "result.html ";
Final string resultencoding = "UTF-8"
Loggingwriter = loggingutils. createwriter (resulthtmlfilename, resultencoding );
Loggingresultsformatter htmlformatter =
New htmlresultformatter (loggingwriter, resultencoding );
Htmlformatter. setscreenshotbaseuri (""); // This is for linking to the screenshots
Htmlformatter. setautomaticscreenshotpath (resultpath );
// Wrap httpcommandprocessor from remote-control
Loggingcommandprocessor myprocessor =
New loggingcommandprocessor (New httpcommandprocessor (your-configs), htmlformatter );
Selenium = new loggingdefaselselenium (myprocessor );
Selenium. Start ();
}
@ After
Public void teardown (){
Selenium. Stop ();
Try {
If (null! = Loggingwriter ){
Loggingwriter. Close ();
}
} Catch (ioexception e ){
// Do nothing
}
}
7. After running successfully, generate the corresponding reports in the specified directory.
VII.
VII. Framework advantages
1. Record the test process. What we see is what we get, all the internal SeleniumProgramThey are all written in javascipt and flexible;
2. You can use the selenium ide recording script to play back the script and use it as the prototype of JUnit code;
3. Support for multiple operating systems;
4. Supports multiple encoding languages. Java,. net, Perl, Python, Ruby
8. Framework weaknesses
1. The recording tool of selenium can only be installed on the Firefox browser. If the system interface is not supported by Firefox, it takes some time to hand-Write the case. However, I recently heard that there is a tool named 360 webtester that supports the recording of IE, and it is a good evaluation in China. I have time to study it.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/congqing2011/archive/2011/02/26/6210553.aspx