autoit +selanium on jenkins does not work - selenium

enter image description hereI have a selenium test implement for web application and implemented autoit to do a folder upload to my application. This folder upload initiates a chrome popup warning which has no title but 2 buttons "Upload" and "Cancel" (default selected). The folder upload is in the control of my application and has title for the popup window. So I could see controlfocus worked on upload folder popup even when my test was deployed on jenkins. But it does not click on the Chrome popup warning
#include <WinAPIFiles.au3>
ControlFocus("Select Folder to Upload","","Edit1")
ControlSetText("Select Folder to Upload","","Edit1","<Myfolder Path>")
sleep(4000)
ControlClick("Select Folder to Upload","","Button1")
sleep(4000)
;this is for the popup warning from chrome
ControlFocus("[CLASS:Edit; INSTANCE:1]","","Edit1")
Send("{LEFT}") <===== this and below does not ever work on jenkins but works on local
execution
Send("{ENTER}")
;sleep(10000)
exit(0)
my selenium code has
String filepath = ".\\uploadfile.bat";
Process p1 = Runtime.getRuntime().exec( filepath );
uploadfile.bat is ....
START /wait c:\AutoIT\uploadfld.exe

As first step run yours AutoIt script, and just after that click the HTML element using selenium.
Do not try to run AutoIt script after clicking the HTML element in selenium, as this stops your selenium because browser waits for file selection.
And as I said in one other cases (question which I answer some time ago), there should be other possibilities to do that without AutoIt, even without invoking the pop up window.

Related

Restart Selenium script without loosing data

I have a classic Selenium script (in jupyter notebook) for scraping a website.I run that script and craweled hundreds of pages (clicking next-next) and finally an exception occured. Browser window is open with that session. Now I want to rerun that script from where I left in the same window maybe, before error occured. How is it possible?
Yes, your code probably starts with opening new browser window and getting the url such as
driver=Chrome(executable_path='chromedriver.exe')
driver.get(url)
Just comment out that lines in the next run and your code will run in the current open window where you left.

How to automate upload file with double click without using send keys in selenium java?

Trying to automate using the below code but not working
Actions actions = new Actions(driver);
fileupoladbtn.sendKeys(System.getProperty("user.dir") +"/Images/zoom_out.jpg");
actions.dragAndDrop(fileupoladbtn, fileupoladbtn1);
what I could understand from your short described question , you need to interact with windows file upload which is not handled by selenium , you need to use auto it scrip and call that in your selenium script.you can download Auto it and SCiTE which is the editor.
below is the autoit file upload script -
Sleep(1000)
ControlFocus("Open","","Edit1")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Send("{Backspace}")
Sleep(1000)
Send($CmdLine[1])
Send("{Enter}")
Sleep(2)
ControlClick("Open","","Button1")
It will be saved when you go to tools and compile it in autoit editor, note the name from here.
once action to popup file upload is done, and Window handler to file upload is visible call above script.
for Java
Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe");
for Python
subprocess.Popen('C:\\Handle\\FileUpload.exe '+File_path, shell=True)
More Details
https://www.autoitscript.com/site/autoit/downloads/
https://www.guru99.com/use-autoit-selenium.html

Screenshot is not loaded in my Jenkins Result Page

My Testcase execution result will be displayed in the form of .html.
When I double click and open the .html file, the testcases results
along with the Pass or Fail screenshot will be displayed.
I am executing the selenium testcases in Mozilla Firefox browser
When I open the .html file from my local machine, the images for
every are loaded without any errors.
When I try to open the same .html file from any other system, images are not loaded.
Can somebody help me out in this issue?
I believe you are not able to view HTML properties of your HTML reports. This is working fine as per default Jenkins behavior.
Run below in Script Console (available in Manage Jenkins) to view HTML and CSS properties:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

automate image upload from windows explore with selenium and AutoIT

I have to automate a scenario like a upload an image from windows explorer to TinyMCE component using Selenium. Since Selenium does not support OS control, I used AutoIt to upload the image.
AutiIt sets the image path to "File name" and seems like it clicks on 'Open' button as well. But the image is not loading to my "source" field.
Here is my Selenium command:
Runtime.getRuntime().exec("C:/XXXXX/src/test/resources/uploadImage.exe");
// Path of the AutoIT script file
AutoIT script:
WinActivate("Open")
Send("C:\LCNGProjects\Screenshots\Images\GifImage1.gif")
Sleep(5000)
Send("{ENTER}")
Refer the attached screenshot
Not sure if I have got the questions correct, Did you compile the script.
Can you please go through link below for script compilation and step by step info how to upload a file.
https://www.guru99.com/use-autoit-selenium.html
You do not need to use AutoIt. Auto will make your script dependable on windows machine only.
Instead of it find element using locator(i.e. xpath) of upload button which is having tag as type="file". Now pass this simple sendKeys with absolute path of your image in your machine like below:-
button2.sendKeys("C:\\UsersDesktop\\logo\\Summit-Logo-900px.png");
Or use
System.getProperty("user.dir"));
Append the path of file exluding your project path and filename inside your project
Example :-
button.sendKeys(System.getProperty("user.dir")+"\\logo\\Summit-Logo-900px.png");
below link contains more option to upload file like below :-
Using SendKeys command.
Using AutoIt scripting.
Using Jacob com interface.
http://www.techbeamers.com/handle-file-upload-selenium-webdriver/#h3
Hope it will help you :)
I'm not going to add full source code here. You can call the AutoIT script using this command inside your test case.
// Call to AutoIT script to upload the image
Runtime.getRuntime().exec("C:\\xxxxx\\src\\test\\resources\\uploadImage.exe");
AutoIT Scrip
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1","C:\xxxx\Images\jpgImage")
ControlClick("Open","","Button1")
For more information refer the following link
https://www.guru99.com/use-autoit-selenium.html

How to download the *.jar file from http:// seleniumhq.org using selenium WebDriver code?

Steps: open the Browser > enter URL http://seleniumhq.org >
Click Download tab > click Download version “2.46.0” link
It opens a dialog window. Click “Save File” button
Note: I have tried download *.xls file example code from URL: http://seleniumeasy.com/selenium-tutorials/how-to-download-a-file-with-webdriver it is working fine in my system. It automatically handling the dialog box and saving the file in destination location.
But the same code not working to download the *.jar file.
Could you please look into this one and help me to resolve this?
If you are downloading Selenium Standalone Server try this:
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive");
If downloading selenium java webdriver:
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
Here is a nice link for a detailed list of file format MIME type list: ClickME