Reputation: 13
I'm using jasmine-spec-reporter to generate xml and html reports for my protractor test cases. I'm wondering if it is possible to also save the html of the tested page. I tried to search but could not find any info about it, I'm surprised no one ever needed it...
Reason in my case is: I'm running a version of the tests on production platform to generate expected results (and would like to save html too), then run actual tests on test platform, comparing results to expected.
Any input would be appreciated!
Upvotes: 1
Views: 107
Reputation: 1408
browser.getPageSource()
Will grab the page source of the current page.
return browser.getPageSource().then((value) => {
var fs = require('fs');
fs.writeFile("a.txt", value, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
})
You can then log it in the report or create a text file with the html.
https://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.getPageSource
To get the entire page
browser.driver.findElement(By.css('body')).getAttribute('innerHTML').then((value)=>{ console.log(value)};)
Upvotes: 0