Learning Selenium a period of time, just at the beginning of the contact did not use the framework but from the basic beginning to write. When learning to a certain point, suddenly wondering if there is something better to be able to show this test result, such as LR performance Test Generation performance report, like the iOS automated test run to show the expected results. In this way, the study of thinking is really important, because the work of many times is their own groping process, such as I now.
For the test framework, the current mainstream is junit and testng. Because I used to learn Java, I have a certain understanding of junit, and for the current use of the testng is the first contact. (for the use of selenium and frameworks, still think that you should learn Java basic syntax first to help the script to write more smoothly.) )
JUnit vs. TestNG
First of all, it is important to choose a framework that suits you. Because it will determine the quality and direction of your future work.
1. JUnit is a unit-testing framework for the Java language. Applies only to unit tests. Inheriting the TestCase class, you can use JUnit for automated testing.
2. TestNG is a new framework for testing Java applications, inspired by JUnit and NUnit, but introduces new features that make them more powerful and easy to use, such as:
1>testng can cover all types of tests: unit, function, end-to-end, integral, etc., and it needs to be JDK5 or higher.
2> and JUnit (4.0) are more than one to add test information to testng.xml files or build.xml.
3> Support Injection
4> more Java and object-oriented features
5 > Separate compile-time test code from Run Configuration/data information.
6> Flexible Run-time Configuration
7> introduced "Test Group"
8 > Comprehensive classes that support testing (for example, by default, there is no need to create a new instance of a test class for each test method).
9> Flexible API Plugin
10> Support for multithreaded testing
TestNG Features
Supports annotations.
TestNG uses more Java and OO features.
Supports testing integrated classes (e.g., by default, no need to create a new test class instance for every test method).
Separates Compile-time test code from Run-time configuration/data info.
Flexible runtime configuration.
Introduces ' test groups '. Once you have compiled your tests, you can just ask TestNG to run all the "front-end" tests, or "fast", "slow", "database" Tests, etc.
Supports Dependent test methods, parallel testing, load testing, and partial failure.
Flexible plug-in API.
Support for multi threaded testing.
testng Installation
1. Open Eclipse,help>install New Soft>add as follows, and click OK to start installing testng,
2. After installing the testng, restart Eclipse to see if it is installed, Help-->about eclipse-->installation Details, as shown in figure:
3.Project, run: Then right key run as-->testng Test:
Above, TestNG was successfully installed in eclipse.
generate test reports for test results
After the testng installation is successful, create a new Suite.xml file in Project NEW:
<suite name= "Seleniumcn.cn.demo" >
<test name= "TEST_SELENIUMCN" >
<classes>
< Class name= "Com.selenium.TestHelloWorldTestNG"/>
<class name= "Com.selenium.TestHelloWorldTestNG_Fail"/ >
</classes>
</test>
</suite>
Right-click the Suite.xml file, runas->testng the Suite so that all the cases in the Suite.xml file are run, and now that project is refreshed, a folder named: Testout is generated. Open the index inside. HTML to see the resulting test report:
The combination of
selenium and testng will greatly visualize our test results and expectations and help us to automate our testing. OK, above.