One of our customers came to us with a question about testing with a file upload.
I quickly responded it was not possible with the way we clear out all of virtual machines. What is a great feature for privacy is not such a great feature for testing file uploads 🙁
But Henry ( see his site here http://people.apache.org/~hchan/ ) was not convinced and came up with a fantastic solution.
This is the resource he passed me.
https://muthutechno.wordpress.com/2014/07/09/uploading-files-in-selenium…
The magic happens on the workstation side (where you are running your script), selenium will take the file you have locally and get it to the remote instance running at CrossBrowserTesting.com
Super cool stuff and once again really good detective work from Henry. Always great to learn something new.
See the article for what your HTML will look like, below is a sample of what your Python script might look like.
from selenium import webdriver
import time
caps = {}
caps[‘browser_api_name’] = ‘Chrome40x64’
caps[‘os_api_name’] = ‘Win8.1’
caps[‘screen_resolution’] = ‘1024×768’
caps[‘record_video’] = ‘true’
caps[‘record_network’] = ‘false’
caps[‘record_snapshot’] = ‘false’
USERNAME=””
AUTHKEY=””
CS = “http://” + USERNAME + “:” + AUTHKEY + “@hub.crossbrowsertesting.com:80/wd/hub”
driver = webdriver.Remote(desired_capabilities=caps,command_executor=CS)
time.sleep(5)
driver.get(“http://SOMEDOMAIN.com/testupload.html”)
time.sleep(5)
e = driver.find_element_by_id(“fileuploadField”)
# this filename is on your local workstation
e.send_keys(“c:\\projects\\2015\\06-jun\\selenium-fileupload\\677px-Mona_Lisa.jpg”)
time.sleep(5)
s = driver.find_element_by_id(“submit”)
s.click()
time.sleep(30)
driver.quit()