Several common processing scenarios for Windows popup in selenium Automation implementation

Source: Internet
Author: User
Tags sikuli

I. Overview

In the use of automation framework selenium implementation, often encounter Windows pop-up box appears, just get started web automation test small partners don't panic Oh!

Two. Several common scenarios for handling Windows pop-up boxes

2.1 Selenium Handling Security dialog box (Windows Security dialog) is replaced with AutoIt

2.1.1 Installation Autoit-v3-setup.exe

2.1.2 The AutoitX3.dll and Jcob.1.18-m2-x86.dll to the C:\windows\System32 path, and if it is a 64-bit system, autoitx3_63 is required. DLLs and Jcob.1.18-m2-x64.dll are placed under the C:\windows\System32 and C:\WINDOWS\SYSWOW64 paths respectively

2.1.3 Register AutoitX3.dll:dos window, enter regsvr32 autoitX3.dll and press ENTER, or enter AutoitX3_64.dll:dos regsvr32 in the 64-bit System registration autoitx3_64 window. DLL and press ENTER

2.1.4 need to introduce jar packages in the project: Autoitx4java.jar and Jacob.jar

The 2.1.5 instance code is as follows

1 /***2      * 3      * @paramTitle of the title Window box (use the installed Autoit64.exe to identify the title of the wind pop-up windows)4      * @paramuserName User Name5      * @parampwd Password6      */7      Public voidAutoithandlewin (String title,string username,string pwd) {8AUTOITX x=NewAutoitx ();9         if(X.winwaitactive (title, "", 20)){Ten             if(x.winexists (title)) { OneX.sleep (500); AX.controlsettext (title, "", edit1,username); -X.controlsettext (title, "", edit1,pwd); -X.controlclick (title, "", Button); the             } -         } -}
View Code

The 2.2 Java program implements automated testing, automatic presentation, or other mouse and keyboard-controlled applications. For this purpose, since JDK1.3 began, it has provided us with a machine for generating native input events human--java.awt.robot;

2.2.1 For example, we can use the robot class analog keyboard to send shortcut keys to operate the IE11 download box Save Press, the instance code is as follows:

1  Public voidRobothandlewin () {2         Try {3Robot robot=NewRobot ();4 robot.keypress (keyevent.vk_alt);5 robot.keypress (keyevent.vk_s);6Robot.delay (500);7 robot.keyrelease (keyevent.vk_s);8 robot.keyrelease (keyevent.vk_alt);9}Catch(awtexception e) {Ten             //TODO auto-generated Catch block One e.printstacktrace (); A         } -}
View Code

2.3 Operating According to

2.3.1 Installation SIKULI-X-1.0RC3 (r905)-win32.exe

2.3.2 Configuring environment variables

Here is a small example of automation. (The first small example of the official input Hello world for the start run) here for open 360 speed browser (the default is Baidu homepage), search box input Sikuli, and then click "Baidu Click" button Search.

The first step, click on the Desktop 360 speed browser icon.

Method One, enter double-click function DoubleClick (), and then through the tool to the desktop icon, enter.

Method Two is very quick, click on the left side of the window double-click Function DoubleClick (), directly into the state. Add functions directly to the script editing area when you are finished.

The second step , we still use the second shortcut, click on the left type (icon, text) function, this interception of the object is Baidu home input box.

Because, the focus of the default positioning is the center of the picture, we want to enter the position on the left side of the input box, so the focus needs to be adjusted. Straight Click on the picture of the input box.

Of course, in this window, we can also adjust the image matching degree, the lower the matching degree of fault tolerance is stronger. Here's a quick explanation:

Everyone knows that the icons of IE7 and IE8 are similar, but they differ. To make the script more portable. For example, this machine is a script recorded with IE7, migrated to another computer only IE 8, because the accuracy is lowered, the script will be IE8 when IE 7来 execution. Of course, some of the situation is lower and not good, such as two icons on the desktop are very familiar with, then the accuracy adjustment is very low, then the script will not be able to identify who is who.

The third step , this step is the same as the first step, but the function to be used here is to click on the function clicking (), click on the "Baidu button".

The following complete script:

Let's run this little script! The sense of accomplishment is the driving force of your interest in this technology.

2.3.3 Click on the Page object according to the truncated picture, the code example is as follows

1  Public voidSikulihandlewin (String pngpath,string envetname) {2Screen screen=NewScreen ();3Pattern image=NewPattern (pngpath);4         if(Envetname.equalsignorecase ("click")){5             Try {6                 if(Screen.exists (image)! =NULL){7 Screen.click (image);8                 }9}Catch(Exception e) {Ten                 //Todo:handle Exception One             } A         } -}
View Code

---------------------------------Technology Changes Life! , qq:770544029

Several common processing scenarios for Windows popup in selenium Automation implementation

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.