webdriver: testing file download

rather than using complicated functions to try and test file downloads, we can use simple logic like if the download is successful, we should see title A and if download fails, we should see title B. Surely, our system wouldn’t spit out the same page title even if the file doesn’t exists. So using phpwebdriver for example, say I am trying to check if the download link is working in the thankyou page:

// thankyou page
$this->assertEquals(self::$session->element('xpath', '//td[@class="product-name"]/small/a')->text(), "Download file now");
// now click on the download file link.
 self::$session->element('xpath', '//td[@class="product-name"]/small/a')->click();
// wait for a 2 secs for the download now prompt.
// if file exists, then I should see the "Order Received" as part of the page title header.
$this->assertRegExp('/Order Received/', self::$session->title());

Like it.? Share it:

Comments are closed.