Use IMacros to automate everyday work

Source: Internet
Author: User
Tags add time stop script

Increase productivity with IMacros's browser add-ons

Introducing IMacros, a powerful tool that uses a simple example to illustrate how to use this tool to complete the operation of a Web page, especially for a large number of repetitive work items that can be more efficient. For testers or developers, this tool can also help manage test case, which is combined with data flow to efficiently perform tests on various business systems.

In any industry, testing has become a necessary part of manufacturing and development processes. Especially in the software industry. In recent years, due to the development of WEB application, the market is a hot topic, although not to the Han Emperor "exclusive Confucianism" eminence, but according to the effective questionnaire survey, the number of Web engineers is the most. With so many people spending so much time every day at work, the cumulative results are staggering and the tools are thriving. Web automated testing, now is not any fresh topic, today, a lot of mature tools we can readily use, compared to many years ago, the current WEB engineer, the efficiency should be far better than ever.
The IMacros described here is a browser add-on that has been proven by countless people as a powerful tool after a long period of development. IMacros as its name, this tool is mainly used by the editor macro (Macros) to manipulate the browser, to achieve the previous need to use the mouse keyboard manual operation.

IMacros Introduction

IMacros is primarily used to operate the Web Browser, which is supported for the main web Browser:ie, Chrome, and Firefox. This article mainly uses FireFox as an example to illustrate.
IMacros after years of development. Features are becoming more advanced. But one thing you might remember first is that the role of this tool is not a almighty-tool, but a focus and its beginning role setting--to manipulate the browser. In this way, when judging what the tool can do and what it cannot do, you can make a general judgment, even if you do not read the instructions.
Plug-ins or libraries with similar functions to IMacros , there are many proven solutions to different needs. Personally feel that relying on the existing browser to achieve the most burthen, can be said to stand on the shoulders of giants, because the development of the browser to eliminate the link, greatly reducing the difficulty of development and code, but also improve the convenience of the application.
If you do not rely on the browser, you must have the program to implement the functionality of the browser. Give a few examples, for example, the LWP inside Perl (Library for WWW in Perl) or Java httpclient, and so on. See the Reference Resources section.

Let's start by explaining how to use this small and powerful tool, IMacros.

Download

The latest version of the IMacros add-on, which can be found in the Reference Resources section.
After opening the screen as below, click Add to Firefox, you can complete the installation.

Figure 1. Download the screen installation

and other Firefox add-on is the same installation method, after clicking on, the following screen will appear.

Figure 2. Installation of the screen

After the installation is restarted, it is ready to complete.

Figure 3. Restart Firefox interface introduction

The following interface will appear after installation. Because Firefox is a hypothetical platform, the following instructions are also given in Firefox as an example. In other browsers, it also has a similar interface and functions, here do not intercept the screen. Here is an introduction to frequently used features.

Figure 4. Introduction to the interface accessories

Click to view larger image

Table 1. Description of the main UI accessory
numbering Description
1 The easy Start button on the Add-on bar (not necessarily arranged in this position), the menu can be toggled on the left to appear/disappear,
2

Here's #Current. IIM is a reserved word that represents the current script. The IIM is the file name of the script file.

The current script means that every time we record a new script, the recorded content is saved here, and each time the record button is pressed, the contents of the file are emptied, and then the content that is currently being recorded is recorded. If you want to save the recorded content, you must save the current script as a different name

3

The 3 tabs here collate 3 categories of functions.

Play: The details of the playback script that have been played.

Rec: recorded details. The core of the feature.

Edit: The script is edited, where the script is saved, and so on.

4 The settings of the tool, where the file is saved, the editor, and other details. IMacros offers a number of options for users to set up according to their needs.
Use

The use of this plugin, it is easy to imagine, as long as the need to use the browser, but also want to automatically operate, you can use this plugin to facilitate the work. The author is more often used, can be divided into 2 categories, which are used for automatic testing, as well as simple daily work of processing, increase work efficiency. Prior to the customer's site, work to develop, testing as the center of gravity, often using IMacros to carry out automated testing, now because of the Department of the project Management to focus on the work, and management system just good is a web system in the intranet, so the IMacros use, are simplifying the tedious daily work.

Automated testing

For a developing WEB application programmer, testing for various business scenarios should be a good tool. The management of the various Test cases is also relatively clear, in the various maintenance development, version upgrade, in addition to the modified code for the UT test, in order to ensure that the entire business process will not be caused by such a modification of unexpected problems, the use of this tool to do business process testing, will be very efficient.

For example, such as user registration, login function, regardless of the background of what language, the front desk has no use of Ajax, for the user is to fill in a few fields after the submission, and then may have an email notification, completed the registration, you can use the ID and password obtained for the next login. At this point, if you want to fill in a lot of fields, each time you modify the program, you need to create a new user to do a test. As long as you have a script like this, you can run it once at the time of debugging. Can be said to be quite simple.

  • Editing management of Scripts

    The ease of editing and management of scripts makes it easy to design scenarios for testing.

    Figure 5. Script List Window

    Management is used in the form of catalogs, which can be categorized at a glance. In addition, for each IIM file naming, you can also make a little effort to define their own naming rules, will greatly improve efficiency.
    In addition, in the operation of various can be fine-tuned parts, in addition to through the interface of the operation, pause, stop, Loop number of settings, by the script to write, but also to the response time measurement, each Click between the set stop time and so on detailed control.
    Remember before the development of the bank's business system, often because of the bank, accounting regulations change, so that the banking system must be constantly updated maintenance.
    Follow each business process to design the script for the test, and then use this script to verify the impact of the change as the system updates. Increased efficiency, but also added to the customer's sense of trust in our team.

  • Support for Data driven Test

    The data driven test, by its very literal means, is to drive the test in the same way. From another point of view, the purpose of the design system is ultimately to manipulate the data. And the data is persisted (persistent) through the database. When you enter a form on a webpage, the input is usually changed after the business process, and we can use this tool to assist in designing the test scenario. Here,IMacros provides the ability to read a CSV file, to connect various types of databases through an interface, and to invoke IMacros in a variety of Script languages. In addition, when compiling the iMacros script, some variables can be used to transfer and control the data. However, according to the author's personal experience, using some template engine (for example, Java Velocity) to read the database, and then dynamically generate iMacros script, is also a very convenient way, the threshold of entry is also relatively low, because there is no need to be familiar with many IMacros script syntax, variables do not need to be controlled in the iMacros script.

  • Retention of test results

    The iMacros script allows us to save screen screenshots (which can be used in a variety of formats) and save screen HTML to save each screen. Prior to the project in the bank, the operation process of the screen, especially the display of the calculation results, it is necessary to complete each process, as one of the products delivered to the customer, the use of this function is quite convenient. When you save a picture or page, the named rules can be set in the script, for example, by time naming, naming the screen name, or combining naming and so on.

The simplicity of daily work

Basically, the same functionality is used when doing automated tests. The daily work according to the business different can be said to be difficult to make classification, the following list a few examples, in the author's daily work often will be used.

Table 2. Examples of use in daily life
Scene Details
Orders issued every month In Excel first tidy up the order data, and then use VBA to generate execution script, using IMacros to put the data in the system's next order page, in addition to ensure that the number is not due to manual filling errors, the speed is very fast.
Download page The author often operation of the system inside, often need to put several intranet page content to save, to suppliers, download save page can also use iMacros script to help execute. Can greatly improve the efficiency.
Fill out the form I often visit some of the sites that need to enter search criteria to filter the information, so that the search conditions cannot be saved, resulting in each access to the new input. With the iMacros script, this solves the problem.
Memory Operation Path Colleagues sometimes ask, when the system is operating, you can record a iMacros script, sent to colleagues, colleagues can be at a glance after execution.
Introduction to the IMacros script

Before recording the script, for the convenience of the presentation, I prepared a simple form interface, which has the following elements. This table lists the controls that we often use, and the rest of the content is centered around this example.

Figure 6. Example to record a script with a simple web site screen

Open the page of the test site, press the Record button as issued, the contents of the record will appear in the above window, and the content of this window is saved in the #Current. IIM .

Figure 7. A picture of the user's operation process is recorded

After the operation, enter the following in the screen. Before add, press the Take screenshot button, then click Add on the page and click Confirm on the next page.

Figure 8. Script setting for screen screenshot during operation

Click on the Confirm button in the example website and then click "Stop" in the control menu to finish recording the script.

Figure 9. Press the stop script to finish recording save

When the recording is complete, the script is recorded in the #Current. IIM This file, if you are satisfied with the results of the recording, we can alias the script to avoid being overwritten the next time we record. Press the Save button

Figure 10. Save Current script

Then enter the file name, save location (in the preset location)

Figure 11. Enter a new file name to save

After you press OK, you will find a new file saved in the window above.

Figure 12. Save the new script in the List window to display the playback script

Next we're going to play the script. Select demo with. IIMand click the Run tab Run button, or simply double-click the demo to run the script.

Figure 13. Run a script that just finished recording

The running picture is too dynamic, so it is not here that the screenshot shows that the result after the run is as follows. Because the process is exactly the same, all of the results are one more identical piece of data.

Figure 14. Script language Introduction to IMacros results after running

Next we click on the demo to use. IIM , and then in the edit Tab, select "Compile Macro" (or use a text editor to save the demo with the location of the . IIM file directly open the file also OK), see IMacros What was recorded for us.

Figure 15. Edit a script that just finished recording

In order to facilitate the explanation, the picture has a combination of processing, the left is a recorded script, the right is what we entered on the page.

Figure 16. What the IMacros is recording

Click to view larger image

The 1 to 15 lines here, according to the 8020 rule, may contain 80% of the most commonly used functions in daily work. The contents of the following lines are briefly described.

  • Visit the representative on the third line of the page to URL GOTO=http://localhost/sample/tblmember_shiplist.php  reach this page. If the destination page has arrived before the script executes, let's say it is typed directly into the address bar, or borrowed from a saved Bookmark, that line can be deleted. In general, if you want to arrive in the pre- IMacros of the reservation page is required after a period of operation (such as the user login to do some of the actions, must be in the Session first to prepare some data), then can not directly specify the link address directly to access, You can manually manipulate the page to the destination before executing the script. The details of this command can be referenced in the following links: Refer to the Resources section.
  • Click on the link on line fourthTAG POS=1 TYPE=A ATTR=TXT:Add

    Represents the action that occurs when you click on the link below:

    Figure 17. The location of the ADD on the screen

    Figure 17 The HTML source code for the link

       <a href= "tblmember_shipadd.php" >Add</a>

    TAG is a command inside a iMacros script. The purpose of this command is to select elements in the current HTML page (element), as to what elements to select, you need to specify the parameters behind them to indicate. The following parameters are used to mark the different attributes of an HTML element to define the location of each element, as if it were a home address.

    For example, Changning District, Shanghai. The city and district here are attributes, and have a feature that reduces the range step-down from top to bottom. Please refer to the table below for detailed instructions.

    Properties Description
    Pos If more than 2 elements share the exact same properties (say, the same building in the same cell), the POS parameters can be used to help clear the location (i.e. the first building in the same building) by different locations. Here, because there is only one element, the parameter value is 1.
    TYPE This parameter is used to indicate what type of HTML Tag is being positioned. In the HTML source code, it can be seen that the type of this HTML tag is a tag (a for anchor), all the parameters here after the type of the value is a.
    More instructions on a Tag can be found in the detailed description: Refer to the Resources section.
    ATTR This parameter is used to indicate what property the HTML Tag is to be positioned in. Because it is the reference to the corresponding Htmltag properties, so you can specify a lot of items, in the HTML source can be seen with href= "tblmember_shipadd.php" properties, as another option, here the Tag property can also be marked as attr=href:tblmember_shipadd.php
    Txt This parameter is used to mark the part of the text enclosed by the tag. HTML source can be seen in the Tag between tags wrapped with Add this text.
  • Form input

    The next step from line 5th to line 12th of the script is to fill out the form

    Figure 18. Recording the parts of a script that are related to form input

    The script here contains more positioning information, just as it was previously stated, in order to correctly mark the location of the HTML element to be manipulated and the content. It can be said that with each type of HTML source, the property is interactive reference. Here is to note that the content of this parameter, represents the form to enter the contents, in doing more flexible use, we may need to edit this parameter, the rest of the parts can be recorded and automatically completed, basically the chance of modification is not big.
    This is also the parameter of the form, because all the form originals are wrapped in the form, so in almost every line of the script you can see the Form=name: Mark indicating which form the original belongs to.

    Properties Description
    CONTENT
    • 1:
      In the case of the text input box, you can see the 5,8,12 line in the script. In lines 5th and 12th, you can see the spaces and line breaks that are often used in text input, in scripts, instead of <SP> to denote half-width spaces, and <BR> to represent line-break symbols
    • 2:
      In the case of Radiobox, you can see the script inside the 6th line, the corresponding HTML source code excerpt as follows
      <input type= "Radio" name= "X_gender" id= "X_gender" value= "{value}" >
      <input type= "Radio" name= "X_gender" id= "X_gender" value= "1" > Male
      <input type= "Radio" name= "X_gender" id= "X_gender" value= "2" > Female
      The CONTENT is not visible in this line because it is used for positioning using POS.
    • 3:
      In the case of the drop-down box, you can see the script in the 7th line, the corresponding HTML source code excerpt as follows
      <select id= "X_area" name= "X_area" >
      <option value= "" selected= "selected" >please select</option>
      <option value= "1" > Huangpu </option>
      <option value= "2" > Putuo </option>
      This is Putuo, so use%2 in the CONTENT to locate it.
    • 4:
      In the case of multi-box, you can see the script in the 9th line, the corresponding HTML source code excerpt as follows
      <select id= "x_habbits[" "Name=" x_habbits[] "multiple=" multiple ">
      <option value= "1" > Reading </option>
      <option value= "2" > See movie </option> This is also a Select tag that belongs to HTML, so you can find that the 7th and 9th lines of the script use a similar targeting method.
    • 5:
      In the case of a Checkbox, you can see the script in the line 10.11, the corresponding HTML source code excerpt as follows
      <input type= "checkbox" Name= "x_media[]" id= "x_media[" "value=" {value} ">
      <input type= "checkbox" Name= "x_media[]" id= "x_media[" "value=" 1 "> TV
      <input type= "checkbox" Name= "x_media[]" id= "x_media[" "value=" 2 "> Newspaper
      In the recorded script used outside the POS, and Radiobox different, but also add the Content=yes, this is because when clicked on the Checkbox, there are 2 possibilities, one is tick, at the point of a tick to uncheck. is caused by the difference between the Radiobox and the action.
    FORM The source code for the HTML in the demo is <form name= "Ftblmember_shipadd" id= "Ftblmember_shipadd" action= "tblmember_shipadd.php" method= " Post
    The script also uses Form=name:ftblmember_shipadd to mark the position of the FORM.
  • Save Picture

    Next is the 13th line of the script.

    SAVEAS type=png folder=* file=*

    This line of script is designed to save screen captures. Here is a script command that uses the SAVEAS. This command has the following attribute parameters.

    properties description
    type here represents the file name to save. In the case of saving the screen screenshot, you can specify the Bmp,png,jpeg three kinds of secondary file name. In addition to saving screenshots, you can also save this screen. Details can be found in the Reference Resources section
    folder saved file locations. You can specify a detailed path, but the part of the space should be replaced with <SP>. If you do not specify, that is, use the same way as the 13th line, then save to the preset path.
    file Save the file name. If you use the same notation as the 13th line, the current file name (as specified by the file name) is represented. The
    can use the + to append more information, for example, the following notation can be used to add time information to the name of the file:
    file=+{{! NOW:DDMMYYYY}}

    The preset directory mentioned above is the one set in the position shown in Figure 19 below.

    Figure 19. The settings for the save path in IMacros

    The picture in the example is saved to this location and saved as the current file name

    in Figure 20. The screenshot file that was saved during the recording
  • Submit Form

    In the script of the 14th, 15 lines to the form of the submit action, basically the same as explained earlier, the use of the TAG command to locate the location of the Submit button, and then run the script, IMacros will automatically to make the action of the submit.

Re-editing after recording is complete

The above introduction has completed how to use the basic IMacros. But the light is so, theIMacros to our function is not very big.
Next, continue with our example, and want to expand a method that uses Excel to manage the user's data and then enter that data into the system.

  • Collation of data

    Here we are going to use Excel to organize the data that needs to be entered. In order to simplify the description and the complexity of the code, only the name and address of the 2 text input boxes as the data can be changed.
    Scenario: The customer gives us a bit of data and wants us to enter it into the business system: (Space has been pre-used <SP> replaced)

    Figure 21. Pre-prepared input data in Excel
  • in combination with the template engine

    The template engine here can have a lot of different options, like the Velocity of Java, is a very powerful and convenient template engine. The purpose of using the template engine is to output the data through the template, and in this case it is output to   IIM   files for execution. To simplify the instructions here, or to use Excel, you're going to write a VBA to make the Excel data output a script.

    Because this example has the need to input the Chinese part, so in the writing process encountered the problem of coding. In short, the iMacros   script supports UTF8 encoding, but VBA's Print method outputs the GB2312 encoding, which in this case causes   IMacros   Unable to identify the content of the script, in order to solve this problem, to refer to   Microsoft ActiveX Data Objects 2.8 Library   This library, and then do not use Print method, Use ADODB instead. Stream to do the output of the Chinese text. After the completion of the VBA is as follows:

    Figure 22. Create a script with the VBA program

    Click to view larger image

  • Generate the IIM file and run it inside the IMacros

    After running the above VBA, the demo is generated with _VBA. IIM This file should appear under the specified directory.
    You can then open the IMacros Control Panel and refresh the list in the following locations.

    Figure 23. Refresh Macro List

    After the refresh, the generated new file will appear in the list, click Edit Macro, you can see the generated content.

    Figure 24. Open a script generated by VBA

    Figure 25. What is generated by VBA

    Click to view larger image

    Next, double-click the demo in the list to build the _vba. IIM , and then watch the IMacros show. After the execution of the screen as follows, for reference.

    Figure 26. The screen after executing the script

    While the saved screen screenshot, in the system preset directory, such as

    Figure 27. Screenshots saved during execution
The simplicity of daily work

Through the above demonstration, it should be understood that this tool saves us a lot of time, as long as the script ready, let it be executed, after a little time, we can reap the results.

The only problem is how to prepare the script, or the need to constantly try to make mistakes, accumulate experience, can become the work of experts.

IMacros's website provides a very clear index, as well as relevant examples. If you want to implement a feature and do not know what to do, you can usually find the relevant answer on it.

Some skills to improve productivity

To improve productivity, the tool also opens up interfaces that can be combined with some of the most popular scripting languages. Please refer to the Resources section for specific details.

[Original link]http://www.ibm.com/developerworks/cn/web/1310_linlg_imacro/

Add this component to play a bit, in fact, and seleniumide function similar

Use IMacros to automate everyday work

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.