File upload with file browse window in Nightwatch - nightwatch.js

Working on a test script in Nightwatch.js that will test the file upload action on the page. The webpage has a button that opens a file browse window to select the file to upload. I can pass the path and the file name into the browse window but cannot access that window or the "open" button in it to select the file and start the upload. Any ideas?

You might do something like this
filePath = process.cwd()+'/uploads/'+ youruploadfile ; assuming process.cwd gives your the current directory the nightwatch is executed
and then set the value (replace by the right element id )
browser.setValue('input[type="file"]',filePath)
Which will set the file you want to upload for that form and you do not require to click and open the file browser dialog as we will have no control over the same via selenium.

Related

Is it possible to get ie to render a document as html with an extension that is not .htm or .html? (Windows)

I am trying to get an html document that's saved on the file system to run through a vbscript first (to check for script injection) and then open in Internet Explorer if the check passes. I have written the vbscript as well as a .bat to call the script, and all of this works when I don't change the file extension (.htm or .html) but do "open with..." and select my .bat file - the vbscript opens it in IE. But when I change the file extension, IE automatically opens the download dialog instead of rendering the html. I want to use a custom extension as a way of only running certain html docs through my script.
So my question is: Is there a way to get Internet Explorer to recognize and render the document in a file with a custom extension?
CatCat's comment about setting the MIME type is the right answer

Display dialog box only once and apply setting for the whole batch of images

I wrote a simple jsx script, which displays a dialog box containing a list of checkboxes and 'Continue' button, which on click executes various commands depending on which items from the list were ticked.
As this script is supposed to be part of an Action Set, I created an action which just executes this script.
When I run the command File > Automate > Batch > The above action on a Folder or opened files, the dialog box shows for every image from the batch.
Is there any way to show this dialog box only once and apply all its settings to the whole batch?
The better way to accomplish this is to add a folder picker to your dialog and modify the script to loop through all images in the folder (or open files, whatever your needs are) rather than attempt to run the script via an action. If you really must have it in an action, the way I have done this before is to write a xml config file that the script will look for and apply the settings from there - skipping the dialog altogether.

Uploading files using ruby / Selenium

I am writing a script where I click on a button (Select Photo) which opens up a file upload (explorer) box. How am I to set my file name?
This is the code I'm using to click on the Select Photo button (ruby)
driver.find_element(:id, "fileUploadButton").click
I've seen some posts that says I do not need to click on the button but to send the path to the file/image I want to upload. So how would I upload a file on c:\temp\mypicture.jpg?
Here's my full and simple code.
driver.navigate.to "http://blah blah" #the real site is an internal site
driver.find_element(:id, "claimGiftButtonDesktop").click
sleep 5
driver.find_element(:id, "fileUploadButton").click
After clicking the fileUploadButton, that's when the explorer window will show. If I manually click on Open or double click on it, then a loading modal shows and the image is shown on the website.
Here is an IDE recording which works. I'm just having problems translating this into ruby.
open /PromoSite
click id=claimGiftButtonDesktop
click id=fileUploadButton
type id=fileInputElem #Value C:\\temp\\file.jpg
click id=viewProductPreviewButton
I've also added a screen shot. I click the button and the File Upload shows up. This should be something easy, so I must not be focusing on the correct id.
As I have no your code, assume we are testing https://encodable.com/uploaddemo/
#driver.navigate.to "https://encodable.com/uploaddemo/"
element = #driver.find_element(:css, 'input[type=file]')
element.send_keys "/full/path/to/file.jpg"
#driver.find_element(:css, 'input[type=button]').click
So, you should send the full path to the input field and press the "submit" button
I know this is coming a year late but I just started writing a script in Selenium/Ruby and it took me some time to figure it out so wanted to post my solution (and it was as simple as 2 lines!):
*the first line inserts the file path WITHOUT clicking on the browse button, key is to separate directories using double back slashes \\
*the second line clicks on the Save/Upload button
driver.find_element(id: "Document_upload").send_keys("C:\\Users\\me\\Desktop\\my_file.txt")
driver.find_element(id: "save").click

Spring, petclinic, Do you want to save this file, or find a program online to open it?

I downloaded the spring mvc petclinic, when I run it, and clicked in the link :
Display all vitiranians
I got a pop up dilog box saying :
Do you want to save this file, or find a program online to open it ?
in the controller that link is defined like this :
#RequestMapping("/vets")
public ModelMap vetsHandler() {
Vets vets = new Vets();
vets.getVetList().addAll(this.clinic.getVets());
return new ModelMap(vets);
}
My question is :
why it does not dsplay vitiranians and just propmpt me withat dialog box ?
any idea or help will be appreciated.
thanks
The application to be used to open a content of a certain type can be customized in some browsers (I know only for Mozilla and Opera):
Mozilla Firefox users
Open Mozilla Firefox
Click Tools and then Options
Within the Options window click Applications
Select the Content Type you wish to adjust. For example, if you want
to change how a .PDF file opens in Firefox, select Adobe Acrobat Document.
In the Action section, change the action to how you wish to open the
file. If you want to download .PDF files instead of opening them,
select Save file.
Opera users
Open Opera
Click Tools and then Preferences
In the Advanced tab click Downloads
Locate and highlight the file extension you wish to adjust. For
example, pdf (or application/pdf). Tip: You can sort these columns.
Once highlighted, click the Edit button.
Within the file type window, specify how you wish for the file to be
handled.

How to display selected file name in VisualC

I created a small MFC application which has a brose button and then a dialog box. on the button event, I am able to successfully open the select file option, but when I select the file, it doesn't get displayed in the Dialog box.
How can I do that?
Please help...
Presumably you are using CFileOpenDialog? - after it returns, you need to get the selected file name from the CFileOpenDialog -
by using
GetModuleFileName(0, PathBuf, PathSize); You can get the pathname and by doing CString PathName = FileDlg.GetPathName(); you can get the path completely.

Resources