ruby - How do you open a zip file using watir-webdriver? -
my test suite has cucumber front end ruby backend, running latest version of watir-webdriver , dependencies atop latest version of osx. cucumber environment setup execute in firefox.
the export feature of our app creates zip file test import feature, need contents of zip file.
my actual test needs unpack zip file , select individual files in use in testing import feature of our web application.
can point me reference can me figure out how write that?
based off experience, download file same way normal user might. first off, click download button or whatever , can access file wherever , check out contents.
assuming downloads go downloads folder default, there simple code can use select downloaded item:
fn = dir.glob("~/downloads/*.zip").max { |a,b| file.ctime(a) <=> file.ctime(b)}
then use unzip
shell command unzip file. no reason add gem mix when can use generic shell commands.
`unzip #{fn}`
then, you'd use dir.glob again filenames of inside unzipped files folder. assuming file named "thing.zip", this:
files = dir.glob("~/downloads/thing/*")
if want files downloaded directly project folder, can try this. prevents popup asking if want save file handy. think still works haven't used in time. above stuff works sure though.
profile = selenium::webdriver::firefox::profile.new download_dir = dir.pwd + "/test_downloads" profile['browser.download.dir'] = download_dir profile['browser.helperapps.neverask.savetodisk'] = "application/zip" b = watir::browser.new. :firefox, :profile => profile
Comments
Post a Comment