teamcity Compile Execution Selenium upload window script defect

Source: Internet
Author: User

Teamcity compiled selenium script, for the Upload window processing only support the use of SendKeys, do not support the simulation by pressing the ENTER key and using AutoIt, even if the local debugging through the script, commit the compilation after the execution, is also an error, The reason is that teamcity compiled the execution of the script in the process, only the background to launch the corresponding browser driver, no real open a browser caused. Finding this flaw also starts with writing an upload courseware test case script.

An upload course test case, functional test is, fill in the basic information of the course, upload the picture of the course, 1, the picture uploaded successfully, the system will prompt "image upload success", and then click the "Select" button, 2, in the pop-up window to select the required as the course courseware file, click "Open" button or press Enter directly, you can select a file, such as 3, the courseware resource upload success, the system will pop up a mask layer, tell the course resources upload success Figure 1 Figure 2 Figure 3 in order to achieve the courseware picture and resource upload, I started to use SendKeys, and then found that the upload image is successful, Upload courseware failed, because the company uploaded courseware is the use of open source control, so the upload file does not support the use of Selenium API SendKeys, so I changed my mind, ready to simulate the function of testing operations:
    1. Click the interface "SELECT" button
    2. In the popup window using Javaapi's robot, simulate the keyboard by pressing CTRL + V and pasting the courseware resource path
    3. Press ENTER again to achieve the upload of the courseware
    4. Determine if the system has a pop-up mask (PS: Here only to determine whether there is a mask in the window specific text appears)
The script for the action steps is as follows
Driver.findelement (By.id ("Updatepicid")). SendKeys ("D:\1.jpg");//Upload ImageAssert.asserttrue (Driver.getpagesource (). Contains ("Upload image succeeded");//determine if there is a success prompt string for uploading picturesDriver.findelement (By.xpath ("//ul/li[5]/div[1]/label/div/object")). Click ();//Click the "select" button This. Usesysclipboard ("D:\1.mp4");//Copy the file path you want to upload to the Clipboard and paste it out and press ENTERAssert.asserttrue (Driver.getpagesource (). Contains ("Upload courseware success");//determine if there is a success prompt string to upload courseware/*** Copy data to clipboard and paste it out *@paramWriteme *@throwsjava.awt.AWTException*/    Public voidUsesysclipboard (String writeme)throwsawtexception {sleeper.sleeptight (800); Robot Robot=NewRobot (); Clipboard Clip=Toolkit.getdefaulttoolkit (). Getsystemclipboard (); Clip.setcontents (NewStringSelection (""),NULL);//emptying the System ClipboardTransferable Ttext =NewStringSelection (Writeme);//Copy the file path to the system ClipboardClip.setcontents (Ttext,NULL); Robot.keypress (Keyevent.vk_control);//simulate pressing the CTRL keyRobot.keypress (KEYEVENT.VK_V);//simulate pressing the V keySleeper.sleeptight (500); Robot.keyrelease (KEYEVENT.VK_V);//Analog Release V-KeyRobot.keyrelease (Keyevent.vk_control);//simulate releasing the CTRL keySleeper.sleeptight (500); Robot.keypress (keyevent.vk_enter);//Analog Press EnterSleeper.sleeptight (500);}
After the script is finished, it is run debugging, very good, local execution of this step of the script run OK, very happy, so submit the script to the company's SVN, and then teamcity to compile the script I submitted, here to illustrate, teamcity in the process of compiling according to the browser type specified in my script, Open the corresponding driver to execute the script, the compilation process will not open the real browser, but found in the teamcity compilation process upload picture step through, but upload the courseware resource step error, errors log display script in Assert.asserttrue ( Driver.getpagesource (). Contains ("Upload courseware successfully! ") error, this situation occurs because the upload courseware step is not successful, so I can not find the mask layer in the string, so I feel strange, theoretically debugging OK script, in the process of teamcity compile execution is not error, so in order to exclude is caused by network delay, I added sleep time, found the same error, at this time I suspect is not teamcity in the process of compiling execution does not supportrobot simulation operation, so I changed the idea, with the help of AUTOIT3 this tool. using AUTOIT3 directly to write a small script and converted to an executable. exe file, the role of this script is to pop up the upload window, enter the file path in the window and click the window "open" key, so the script becomes the following
Driver.findelement (By.xpath ("//ul/li[5]/div[1]/label/div/object")). Click (); // Click the "select" button Runtime.getruntime (). EXEC ("D:1.exe"); // perform an. exe file Upload courseware Assert.asserttrue (Driver.getpagesource (). Contains ("Upload courseware successfully! "); Determine if there is a success prompt string for uploading courseware
Then the local debugging can run through, but submit teamcity compile or error, this time I ruled out the previous idea "teamcity in the process of compiling execution does not support robot simulation operation" this hypothesis. This time I wonder if teamcity compile execution without opening the real browser, causing me to upload courseware resources failed, in order to prove my hypothesis, I upload the course picture script is also changed to use the simulation keyboard copy and paste operation and combine enter keyboard to achieve, without SendKeys, The script is modified as follows
 driver.findelement (by.id ("Updatepicid")). Click (); //  Click the "Upload Picture" button  this . Usesysclipboard ("D:\1.jpg"); //  upload a picture by copying and pasting  Assert.asserttrue (Driver.getpagesource (). Contains ("Upload image succeeded"); //  driver.findelement (By.xpath ("//ul/li[5]/div[1]/label/div/ Object "). Click (); //  Click the "select" button  Runtime.getruntime (). EXEC ("D:1.exe"); //  execute. exe file Upload courseware  Assert.asserttrue (Driver.getpagesource (). Contains ("Upload courseware successfully! ")); //  
Sure enough teamcity in the compile time on the error, can not find the "Picture upload success" This string, this time I have determined my hypothesis "teamcity compiled selenium script, for the Upload window processing only support SendKeys use, Impersonation is not supported by pressing the ENTER key and using operations such as AutoIt "this hypothesis

teamcity Compile Execution Selenium upload window script defect

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.