From 133d11368459f2af51c80fd05be5cdc3336797b1 Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Mon, 24 Feb 2014 19:22:18 -0500 Subject: [PATCH] Implementing ITakesScreenshot in RemoteWebDriver base class instead of subclasses --- dotnet/src/webdriver/Chrome/ChromeDriver.cs | 18 +----------------- dotnet/src/webdriver/Firefox/FirefoxDriver.cs | 18 +----------------- .../src/webdriver/IE/InternetExplorerDriver.cs | 18 +----------------- .../src/webdriver/PhantomJS/PhantomJSDriver.cs | 18 +----------------- dotnet/src/webdriver/Remote/RemoteWebDriver.cs | 18 +++++++++++++++++- dotnet/src/webdriver/Safari/SafariDriver.cs | 16 +--------------- 6 files changed, 22 insertions(+), 84 deletions(-) diff --git a/dotnet/src/webdriver/Chrome/ChromeDriver.cs b/dotnet/src/webdriver/Chrome/ChromeDriver.cs index 2b3c84422bfa9..b0057404bfd68 100644 --- a/dotnet/src/webdriver/Chrome/ChromeDriver.cs +++ b/dotnet/src/webdriver/Chrome/ChromeDriver.cs @@ -57,7 +57,7 @@ namespace OpenQA.Selenium.Chrome /// } /// /// - public class ChromeDriver : RemoteWebDriver, ITakesScreenshot + public class ChromeDriver : RemoteWebDriver { /// /// Accept untrusted SSL Certificates @@ -153,21 +153,5 @@ public override IFileDetector FileDetector get { return base.FileDetector; } set { } } - - #region ITakesScreenshot Members - /// - /// Gets a object representing the image of the page on the screen. - /// - /// A object containing the image. - public Screenshot GetScreenshot() - { - // Get the screenshot as base64. - Response screenshotResponse = this.Execute(DriverCommand.Screenshot, null); - string base64 = screenshotResponse.Value.ToString(); - - // ... and convert it. - return new Screenshot(base64); - } - #endregion } } diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs index 96c9aa3bfc82a..a7bbeb944a0c8 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs @@ -71,7 +71,7 @@ namespace OpenQA.Selenium.Firefox /// } /// /// - public class FirefoxDriver : RemoteWebDriver, ITakesScreenshot + public class FirefoxDriver : RemoteWebDriver { #region Public members /// @@ -208,22 +208,6 @@ protected FirefoxProfile Profile } #endregion - #region ITakesScreenshot Members - /// - /// Gets a object representing the image of the page on the screen. - /// - /// A object containing the image. - public Screenshot GetScreenshot() - { - // Get the screenshot as base64. - Response screenshotResponse = Execute(DriverCommand.Screenshot, null); - string base64 = screenshotResponse.Value.ToString(); - - // ... and convert it. - return new Screenshot(base64); - } - #endregion - #region Support methods /// /// In derived classes, the method prepares the environment for test execution. diff --git a/dotnet/src/webdriver/IE/InternetExplorerDriver.cs b/dotnet/src/webdriver/IE/InternetExplorerDriver.cs index f4fff081b8a39..80bb79bfa13c0 100644 --- a/dotnet/src/webdriver/IE/InternetExplorerDriver.cs +++ b/dotnet/src/webdriver/IE/InternetExplorerDriver.cs @@ -65,7 +65,7 @@ namespace OpenQA.Selenium.IE /// } /// /// - public class InternetExplorerDriver : RemoteWebDriver, ITakesScreenshot + public class InternetExplorerDriver : RemoteWebDriver { /// /// Initializes a new instance of the InternetExplorerDriver class. @@ -156,21 +156,5 @@ public override IFileDetector FileDetector get { return base.FileDetector; } set { } } - - #region ITakesScreenshot Members - /// - /// Gets a object representing the image of the page on the screen. - /// - /// A object containing the image. - public Screenshot GetScreenshot() - { - // Get the screenshot as base64. - Response screenshotResponse = Execute(DriverCommand.Screenshot, null); - string base64 = screenshotResponse.Value.ToString(); - - // ... and convert it. - return new Screenshot(base64); - } - #endregion } } diff --git a/dotnet/src/webdriver/PhantomJS/PhantomJSDriver.cs b/dotnet/src/webdriver/PhantomJS/PhantomJSDriver.cs index 9683ebb9db799..fc2aa6bbafe53 100644 --- a/dotnet/src/webdriver/PhantomJS/PhantomJSDriver.cs +++ b/dotnet/src/webdriver/PhantomJS/PhantomJSDriver.cs @@ -63,7 +63,7 @@ namespace OpenQA.Selenium.PhantomJS /// } /// /// - public class PhantomJSDriver : RemoteWebDriver, ITakesScreenshot + public class PhantomJSDriver : RemoteWebDriver { /// /// Command name of the PhantomJS-specific command to execute native script in PhantomJS. @@ -202,21 +202,5 @@ public object ExecutePhantomJS(string script, params object[] args) { return this.ExecuteScriptCommand(script, CommandExecutePhantomScript, args); } - - #region ITakesScreenshot Members - /// - /// Gets a object representing the image of the page on the screen. - /// - /// A object containing the image. - public Screenshot GetScreenshot() - { - // Get the screenshot as base64. - Response screenshotResponse = Execute(DriverCommand.Screenshot, null); - string base64 = screenshotResponse.Value.ToString(); - - // ... and convert it. - return new Screenshot(base64); - } - #endregion } } diff --git a/dotnet/src/webdriver/Remote/RemoteWebDriver.cs b/dotnet/src/webdriver/Remote/RemoteWebDriver.cs index caade84058e0a..60779cb104a69 100644 --- a/dotnet/src/webdriver/Remote/RemoteWebDriver.cs +++ b/dotnet/src/webdriver/Remote/RemoteWebDriver.cs @@ -60,7 +60,7 @@ namespace OpenQA.Selenium.Remote /// } /// /// - public class RemoteWebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, IHasInputDevices, IHasCapabilities, IAllowsFileDetection + public class RemoteWebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, ITakesScreenshot, IHasInputDevices, IHasCapabilities, IAllowsFileDetection { /// /// The default command timeout for HTTP requests in a RemoteWebDriver instance. @@ -704,6 +704,22 @@ public ReadOnlyCollection FindElementsByCssSelector(string cssSelec } #endregion + #region ITakesScreenshot Members + /// + /// Gets a object representing the image of the page on the screen. + /// + /// A object containing the image. + public Screenshot GetScreenshot() + { + // Get the screenshot as base64. + Response screenshotResponse = Execute(DriverCommand.Screenshot, null); + string base64 = screenshotResponse.Value.ToString(); + + // ... and convert it. + return new Screenshot(base64); + } + #endregion + #region IDisposable Members /// diff --git a/dotnet/src/webdriver/Safari/SafariDriver.cs b/dotnet/src/webdriver/Safari/SafariDriver.cs index e33e446245a66..160b306a28a03 100644 --- a/dotnet/src/webdriver/Safari/SafariDriver.cs +++ b/dotnet/src/webdriver/Safari/SafariDriver.cs @@ -63,7 +63,7 @@ namespace OpenQA.Selenium.Safari /// } /// /// - public class SafariDriver : RemoteWebDriver, ITakesScreenshot + public class SafariDriver : RemoteWebDriver { /// /// Initializes a new instance of the class. @@ -97,19 +97,5 @@ public override IFileDetector FileDetector get { return base.FileDetector; } set { } } - - /// - /// Gets a object representing the image of the page on the screen. - /// - /// A object containing the image. - public Screenshot GetScreenshot() - { - // Get the screenshot as base64. - Response screenshotResponse = Execute(DriverCommand.Screenshot, null); - string base64 = screenshotResponse.Value.ToString(); - - // ... and convert it. - return new Screenshot(base64); - } } }