In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use Watij, an automated testing tool for Web, this article introduces in detail the corresponding analysis and solutions to this problem, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
With the continuous maturity of the software industry, software quality assurance has been paid more and more attention by software enterprises and is regarded as the life of software enterprises. As an important means of software quality assurance, software testing is directly related to software quality, development cycle and development cost. it is paid more and more attention and runs through the whole life cycle of software development and maintenance. As an important branch of software testing, software automated testing has attracted wide attention of testing technicians and become the direction of software testing because of its irreplaceable advantages, such as high degree of automation, strong practicability, high testing efficiency and so on. An endless stream of software automated testing technologies and software automated testing frameworks are being widely developed and used, and play a prominent role in software testing automation. With the emergence of which automated testing scheme to choose, testers need a powerful and easy-to-use automated testing tool to assist testers to build a test framework and design automatic test programs. and reduce the development and maintenance cost of the automated test program as much as possible. Watij (Web Application Testing in Java) introduced in this article is an excellent open source tool for developing automated testing programs based on Web applications. It uses Java language, provides a lightweight automated test program framework and rich program development libraries, and effectively accelerates the development of automated test programs.
First of all, this paper briefly introduces some main functions and features of Watij, and then introduces the installation and configuration process of Watij.
A brief introduction to Watij
With the wide application of Web products, there are more and more applications with Web as the core in the new mode solutions. the architecture of many companies adopt the Bamp S mode, as well as the application of Web, so the testing of Web products becomes more and more important. How to carry out automatic testing of Web products has become one of the hot issues in today's society.
The testing method of Web should cover all aspects of Web program as far as possible, and the testing technology should also be combined with the application characteristics of Web products on the basis of inheriting the traditional testing. This paper introduces a new automated testing tool based on Web-Watij. Watij is the abbreviation of Web Application Testing in Java. Watij is an open source automated testing framework implemented in Java programming language. Compared with other automated testing frameworks, it is compact and flexible. Watij also provides powerful functions to meet the needs of automated testers in all aspects.
Using the automated testing framework of Watij, automation developers can use Java programming language to develop automated test scripts for products. Watij has a relatively convenient development mode, and Watij provides rich development libraries that encapsulate most of the HTML object types, including browser window windows,button,link,dialog,image,table,div, to facilitate testers to quickly build automated test programs. At the same time, it provides a large number of application methods and application interfaces, these application interface functions include almost all the methods for web page operation. Developers can call these methods to use them easily. In addition, Watij has the characteristics of high efficiency and speed, developers only need to use the methods provided to write test scripts and execute modified scripts, in the test running process as if the real users are operating, so that the automated testing work is almost the same as human manual testing. The application of Watij-based automated testing framework can make the development of automated scripts easier and more practical.
Installation and configuration of Watij
In order to explain the Watij automated testing framework in more detail, the following will introduce the installation and configuration process of Watij, so that developers can use Watij this automated testing framework for automated testing work more quickly and conveniently.
Install the ◆ software package and extract it.
Download address of ◆ Watij_release_3.2.1: http://sourceforge.net/projects/Watij/files/
◆ copies the jniwrap.dll in the file to C:\ windows\ system32\ directory.
◆ opens a Java IDE (such as Eclipse) and creates a new project.
◆ loads the Watij.jar and all jar packages under the lib directory into the classpath of the project, as shown in figure 1.
The specific steps to add a jar package are as follows:
Open New- > Project, select "Java Project", and click "Next"
Enter "Watij" in "Project Name" and click "Next"
Select the option for "Libraries" in "Java Settings" and click "Add External JARs"
Add "Watij.jar" and all the jar under the lib directory, and click "Finish".
Create a JUnit TestCase and make sure to include the phrase "import static Watij.finders.SymbolFactory.\ *;"
Figure 1. Import schematic diagram of jar package
First of all, this section introduces the application method of Watij, and then introduces the use of Watij through a specific application example. Since Watij only supports IE browsers at present, the following contents are based on Windows platform. In addition, RFT (Rational Functional Tester) is an advanced and automated functional and regression testing tool for testers and GUI developers, so this paper uses RFT as the Java IDE of Watij. Then the article briefly introduces the use of Watij BeanShell. * this section briefly compares and explains the two popular automated testing frameworks, Watij and Selenium, and explains the difference and relationship between them, as well as their respective application scope and fields, and shows under what circumstances the application of that automated testing framework will make it play a greater role.
Application method of Watij
First of all, a brief introduction of the function of Watij. Watij can drive HTML's Web application on browsers, and it doesn't need plug-in services like Active X, JavaApplets, Macromedia Flash and so on.
In Web-based automated testing, how to obtain the properties of web objects is a key step in the development of GUI automated testing programs. Because Watij itself does not provide an object catcher similar to Object Capture in RFT, but in the development of Watij programs, we can use some third-party HTML viewers running on the browser side to obtain web page objects in order to view the structure of web pages and object properties, which will make our development work more convenient. For IE browsers, you can install Microsoft IE Explorer Develop Toolbar. If you are using a version of IE browser above 8.0, you can also click F12 and select developer tools to view the properties of an object.
When writing automation scripts using Watij, developers need to use a programming language like XPath to view or locate the object properties to be used. XPath is a language for finding information in XML documents. It is used to navigate through elements and attributes in XML documents. In this way, developers can effectively develop and apply automated scripts.
Application example of Watij
1. After the project is established, you need to create a new "Jnit Test Case" (shown in figure 2). For example, enter "Name" as "TestWatijIBM" (figure 3), and click "Finish". You can create a new script, and you can write programs and automate testing.
Figure 2. New "Junit Test Case"
Figure 3. New Junit Test Case interface
two。 Below we take "IBM" as the keyword to conduct Baidu search operation as an example to introduce.
Listing 1. Baidu search with "IBM" as the keyword
Import static watij.finders.SymbolFactory.name; import junit.framework.TestCase; import watij.runtime.ie.IE; public class TestWatijIBM extends TestCase {public void testgooglesearch () throws Exception {IE ie = new IE (); / / Open IE browser ie.start (); / / go to Baidu homepage ie.goTo ("www.baidu.com") / enter "IBM" ie.textField (name, "wd") .set ("IBM") in the input box; / / Click "Baidu" to find ie.button ("Baidu") .click (); / / wait 3 seconds ie.wait (3);}}
3. Run: after entering the above code and saving it, select "Run as"-> "JUnit Test", as shown in figure 4.
Figure 4. Run the code
4. Execution result: if the execution process does not report an error, the JUnit execution status is displayed in green (shown in figure 5), and the main search interface of Baidu can be opened to retrieve the web page with the keyword "IBM" (as shown in figure 6).
Figure 5. Running result diagram
Figure 6. Run the Baidu interface to retrieve the image
5. Specific code interpretation
IE ie = new IE (); IE object instantiation
Ie.start (); launch the IE browser
Ie.goTo ("www.ibm.com"); go to the www.baidu.com home page
Ie.textField (name, "wd") .set ("IBM"); enter what to find in the input box: "IBM"
Ie.button ("Baidu"). Click (); use the click function to click on the "Baidu" Button
In addition, Watij provides a variety of common Web object recognition and operation support, such as: window control (* minimize and minimize operation), hyperlink click, multi-box selection, CheckBox selection and clear, RadioBox selection and clear, drop-down box and list box selection, text box input, picture and various forms insertion and deletion, various button clicks, Frame access and pop-up window control.
Introduction of Watij BeanShell
Watij provides BeanShell development tools, which makes it convenient for developers to write scripts for automated testing or to debug scripts.
The steps are as follows:
Double-click launchWatijBeanShell.bat or use the command line to enter the BeanShell interface
Figure 7 shows executing the launchWatijBeanShell.bat command with the command line.
Figure 8 shows the operation interface of BeanShell. The operation interface provided by BeanShell has the advantages of convenient operation and simplicity.
Figure 7. Command line executes launchWatijBeanShell.bat
Figure 8. BeanShell interface
Input scripting language into bsh Workspace for related testing work.
Figure 9. Use BeanShell to perform Baidu search operation
What needs to be noted is that BeanShell is carried out step by step, that is, every step of bsh needs to be performed, which makes it convenient for developers to carry out relevant debug operations on the code, so that developers can easily debug the program. BeanShell also provides the corresponding font setting function, developers can make corresponding font settings according to their own needs.
Comparison between Watij and Selenium
The following article will introduce the similarities and differences between Watij and Selenium. Watij and Selenium are both open source tools that can be used for automated testing of web pages. Both of them have their own characteristics and advantages. What are the similarities and differences between them and how to choose? First, both Watij and Selenium run the script directly in the browser and allow the browser to be minimized while the script is running, which means that there is no need to consume a machine's resources for automated testing. Second, both need to use XPath to write scripts, so users are required to have basic knowledge of XPath. However, there are some differences in scripting, and the following article will briefly illustrate the code that performs the same function.
Listing 2 is the code to perform a web login operation using Watij:
Listing 2. Code listing for performing a login page operation
Import junit.framework.TestCase; import static watij.finders.SymbolFactory.name; import watij.runtime.ie.IE; public class TestConcord extends TestCase {public void testconcordfunction () throws Exception {IE ie = new IE (); / / Open IE browser ie.start (); / / go to concord77 ie.goTo ("http://concord77.cn.ibm.com/files/app?lang=en_US#/pinnedfiles");" / / window * * ie.maximize (); / / Security authentication ie.link (name, "overridelink"). Click (); / / enter the user name and password ie.textField (name, "j_username"). Set ("Abdul_000_006") in the input box; ie.textField (name, "j_password"). Set ("passw0rd") / / Click to log in to ie.button ("login") .click (); / / Save the result graph ie.screenCapture ("D:\\ Savelogin.png");}}
Because this article mainly introduces the automated testing framework of Watij, it does not involve the complete execution code of Selenium. If you write the above functions in the Selenium scripting language, the difference is that Selenium must be typed with a complete XPath statement before it can be written and executed.
For example:
Click on a link: ie.link (name, "overridelink") .click () for Watij scripting language execution
Selenium scripting language execution Click a link: Selenium.click ("/ / a [@ name='overridelink']")
Compared to this, the Watij code will be clearer, more flexible and easier to understand.
In addition, it has a faster execution speed than Selenium,Watij. Because Watij is a file that calls .dll directly, you don't need to add another container to load, but you need to start a jetty container. Therefore, Watij is more direct than the Selenium calling procedure, so it runs faster than Selenium. In addition, Selenium does not support pop-up windows, uploads, downloads and other functions well, so it is often necessary to use third-party toolkits, such as AutoIt3,Watij is better than Selenium; in this respect. In addition, Watij provides the method of screenshot, which Selenium does not have at present. However, Watij currently only supports IE browsers, which is the advantage of Selenium. Selenium can support multiple browsers, such as IE,Firefox, Safari, and so on. In addition, Selenium provides the function of recording and playback scripts, and can convert recorded scripts into various mainstream programming languages, while Watij does not provide this feature.
So, when testers are testing products based on IE browsers, Watij is obviously more advantageous, but when testers are testing products based on multiple browsers, or when they need to test browser-to-browser compatibility, Selenium will obviously be a better choice.
Characteristics and advantages of Watij
Watij provides a set of pure Java API based on Watir for automated testing of Web applications. Watij automates testing through a real browser.
Web automated testing is implemented in two ways: * protocol testing, which is based on HTTP protocol, sends a request to the server through get or post, and then parses and verifies the result data returned from the server. The second method is based on browser-side testing, which is tested by launching a real browser environment and automatically performing browser-side related operations (such as clicking buttons, entering text boxes, and selecting list boxes, etc.). As a pure Java API Web automated testing tool on sourceforge, Watij works on the principle of the second testing method. It is a completely open source free software package and has excellent performance in web element positioning and cross-platform deployment.
The Watij automated testing framework also has the following advantages:
◆ seems to imitate real users to operate on the web page, and it has a faster running speed.
◆ Watij obtains the original data of the web page when operating on the web page, so that the development and verification of automated scripts can be carried out more accurately and objectively.
◆ Watij can be used with any Java IDE, and their configuration process is very simple, saving developers from wasting a lot of time and effort on configuring the environment.
Compared with other Web-based automated testing tools, ◆ Watij has better execution results and improves the productivity of developers.
◆ Watij provides good Debug tools and provides convenience for developers to debug.
When the ◆ Watij program is running, it allows testers to access other web pages or perform other operations on the test machine without affecting the results of object recognition.
This is the answer to the question about how to use Watij, an automated testing tool for Web. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.