-
Notifications
You must be signed in to change notification settings - Fork 131
Screen shots full desktop selenium PageSource saving
Jakub Raczek edited this page Apr 21, 2020
·
4 revisions
Our framework allows you to take screenshots: full desktop, selenium full browser, screenshots of elements. It also allows you to save page source.
<?xml version="1.0" encoding="utf-8"?>
...
<!--Screenshots and logging-->
<add key="FullDesktopScreenShotEnabled" value="true"/>
<add key="SeleniumScreenShotEnabled" value="true"/>
<add key="GetPageSourceEnabled" value="true"/>
...
</configuration>
Folder where screenshots will be saved is also set in in app.config file:
<?xml version="1.0" encoding="utf-8"?>
...
<!--Downloaded files, screenshots and page source location-->
<add key="UseCurrentDirectory" value="true"/>
<add key="ScreenShotFolder" value="\TestOutput"/>
<add key="PageSourceFolder" value="\TestOutput"/>
...
</configuration>
Screenshots of elements can be saved to allow you images comparison with e.g baseline:
var el = this.Driver.GetElement(this.menu);
TakeScreenShot.TakeScreenShotOfElement(el, TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");
more details here
Screenshots of specific element within iframe can be taken by passing location of iframe to TakeScreenShotOfElement method:
var iFrame = this.Driver.GetElement(this.iframe);
int x = iFrame.Location.X;
int y = iFrame.Location.Y;
this.Driver.SwitchTo().Frame(0);
var el = this.Driver.GetElement(this.elelemtInIFrame);
TakeScreenShot.TakeScreenShotOfElement(x, y, el, TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");
more details here
Test example of comparing screen shot of elements using ImageMagick, more details here
[Test]
public void TakingScreehShotsOfElementInIFrameTest()
{
var internetPage = new InternetPage(this.DriverContext).OpenHomePage();
internetPage.GoToIFramePage();
IFramePage page = new IFramePage(this.DriverContext);
var path = page.TakeScreenShotsOfTextInIFrame(TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "TextWithinIFrame" + BaseConfiguration.TestBrowser);
var path2 = TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder + "\\TextWithinIFrameChromeError.png";
bool flag = true;
using (var img1 = new MagickImage(path))
{
using (var img2 = new MagickImage(path2))
{
using (var imgDiff = new MagickImage())
{
img1.Compose = CompositeOperator.Src;
img1.Compare(img2, new ErrorMetric(), imgDiff);
flag = img1.Equals(img2);
imgDiff.Write(TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder + "\\" + BaseConfiguration.TestBrowser + "TextWithinIFrameDIFF.png");
}
}
}
Assert.IsFalse(flag);
}
Result of image comparison:
Expected result:
Actual result:
Result with marked differences:
- Home
- Getting started
- Parallel tests execution
- MsTest DataDriven tests from Xml and CSV files
- NUnit DataDriven tests from Xml, CSV and Excel files
- Comparing files by NUnit DataDriven tests
- Visual Testing
- Screen shots: full desktop, selenium. PageSource saving
- Verify-asserts without stop tests
- Downloading files
- Helpers
- Override browser profile preferences, install browser extensions, Headless mode
- Debugging Test.Automation framework
- Logging
- Performance measures
- Webdriver Extends
- More common locators
- Selenium-Grid-support
- Advanced Browser Capabilities and Options
- AngularJS synchronization
- Update App.config or appsettings.json
- Cross browser parallel test execution with testing-Cloud-Providers\SeleniumGrid
- Verifying Javascript Errors from browser
- Enabling Performance Log for Chrome
- Azure DevOps Support
- Edge browser Support
- Downloading and running Selenium Grid with Powershell
- Run Ocaramba tests with Docker container
- HTTP auth in Internet explorer
- ExtentReports Support