diff --git a/Src/MvcPages/BrowserAdapter.cs b/Src/MvcPages/BrowserAdapter.cs index f49a9fb..8328680 100644 --- a/Src/MvcPages/BrowserAdapter.cs +++ b/Src/MvcPages/BrowserAdapter.cs @@ -183,12 +183,28 @@ public MvcWebForm GetForm(string formId) return new MvcWebForm(formElement, Driver, supportedInputsAdapters, this.NumberOfInputSetRetries, this.AfterFieldValueSetAction); } + public TCustomForm GetCustomMvcForm(string formId) where TCustomForm : MvcWebForm, new() + { + var form = new TCustomForm(); + var formElement = this.Driver.GetStableAccessibleElementById(formId); + form.Init(formElement, Driver, supportedInputsAdapters, this.NumberOfInputSetRetries, this.AfterFieldValueSetAction); + return form; + } + public WebForm GetForm(string formId) { var formElement = this.Driver.GetStableAccessibleElementById(formId); return new WebForm(formElement, Driver, supportedInputsAdapters, this.NumberOfInputSetRetries, this.AfterFieldValueSetAction); } + public TCustomForm GetCustomForm(string formId) where TCustomForm : WebForm, new() + { + var formElement = this.Driver.GetStableAccessibleElementByInScope(By.TagName("form"), Driver); + var form = new TCustomForm(); + form.Init(formElement, Driver, supportedInputsAdapters, this.NumberOfInputSetRetries, this.AfterFieldValueSetAction); + return form; + } + public WebForm GetForm() { var formElement = this.Driver.GetStableAccessibleElementByInScope(By.TagName("form"), Driver); @@ -213,6 +229,15 @@ public IPageFragment GetPageFragmentById(string elementId) return new PageFragment(Driver, pageFragment); } + public TCustomPageFragment GetCustomPageFragmentById(string elementId) + where TCustomPageFragment : PageFragment, new() + { + var element = Driver.GetStableAccessibleElementById(elementId); + var pageFragment = new TCustomPageFragment(); + pageFragment.Init(Driver, element); + return pageFragment; + } + public void RefreshPage() { this.navigator.RefreshPage(); @@ -404,12 +429,34 @@ public interface IBrowserAdapter : IPageFragment, IBrowserCamera, IDisposable, MvcWebForm GetForm(string formId); + /// + /// Return object that inherits from strongly typed adapter for web form with given id + /// + /// Inherited object type + /// Model connected with form + /// Id of expected form + /// + /// This method allows to create custom objects that inherit from + /// + TCustomForm GetCustomMvcForm(string formId) where TCustomForm : MvcWebForm, new(); + /// /// Return weakly typed adapter for web form with given id /// /// Id of expected form WebForm GetForm(string formId); + + /// + /// Return object that inherits from weakly typed adapter for web form with given id + /// + /// Class that derive from WebForm + /// Id of expected form + /// + /// This method allows to create custom objects that inherit from + /// + TCustomForm GetCustomForm(string formId) where TCustomForm : WebForm, new(); + /// /// Refresh page /// @@ -434,6 +481,13 @@ public interface IBrowserAdapter : IPageFragment, IBrowserCamera, IDisposable, /// Id of expected element IPageFragment GetPageFragmentById(string elementId); + + /// + /// Return page fragment with given id + /// + /// Id of expected element + TCustomPageFragment GetCustomPageFragmentById(string elementId) where TCustomPageFragment:PageFragment, new(); + /// /// Stop execution until element with given id appear /// @@ -515,5 +569,7 @@ public interface IBrowserAdapter : IPageFragment, IBrowserCamera, IDisposable, /// Action to invoke when finish downloading. Action parameter is a path to downloaded file, /// void DownloadFileWith(Action action, Action downloadCallback = null, int downloadTimeoutInSeconds = 60); + + WebForm GetForm(); } } \ No newline at end of file diff --git a/Src/MvcPages/WebPages/PageFragment.cs b/Src/MvcPages/WebPages/PageFragment.cs index 20bc24e..e9c6dda 100644 --- a/Src/MvcPages/WebPages/PageFragment.cs +++ b/Src/MvcPages/WebPages/PageFragment.cs @@ -1,6 +1,5 @@ using System; using System.Drawing; -using System.IO; using OpenQA.Selenium; using OpenQA.Selenium.Internal; using OpenQA.Selenium.Remote; @@ -12,8 +11,8 @@ namespace Tellurium.MvcPages.WebPages { public class PageFragment : IPageFragment { - protected readonly RemoteWebDriver Driver; - protected readonly IWebElement WebElement; + protected RemoteWebDriver Driver; + protected IWebElement WebElement; public PageFragment(RemoteWebDriver driver, IWebElement webElement) { @@ -21,6 +20,16 @@ public PageFragment(RemoteWebDriver driver, IWebElement webElement) this.WebElement = webElement; } + protected PageFragment() + { + } + + public void Init(RemoteWebDriver driver, IWebElement webElement) + { + this.Driver = driver; + this.WebElement = webElement; + } + public void Click() { this.Driver.ClickOn(this.WebElement); @@ -141,11 +150,11 @@ private byte[] TakeSceenshotManually() { var wholePageScreenshot = Driver.GetScreenshot(); var imageScreen = wholePageScreenshot.AsByteArray.ToBitmap(); - var webElementArea = GetWebElementAreaContrainedTo(imageScreen); + var webElementArea = GetWebElementAreaConstrainedTo(imageScreen); return imageScreen.Clone(webElementArea, imageScreen.PixelFormat).ToBytes(); } - private Rectangle GetWebElementAreaContrainedTo(Bitmap imageScreen) + private Rectangle GetWebElementAreaConstrainedTo(Bitmap imageScreen) { var originalLocation = this.WebElement.Location; var originalSize = this.WebElement.Size; diff --git a/Src/MvcPages/WebPages/WebForms/MvcWebForm.cs b/Src/MvcPages/WebPages/WebForms/MvcWebForm.cs index 1c4476e..5907e33 100644 --- a/Src/MvcPages/WebPages/WebForms/MvcWebForm.cs +++ b/Src/MvcPages/WebPages/WebForms/MvcWebForm.cs @@ -18,6 +18,11 @@ public MvcWebForm(IWebElement webElement, RemoteWebDriver driver, List /// Set value for field indicated by expression /// diff --git a/Src/MvcPages/WebPages/WebForms/WebForm.cs b/Src/MvcPages/WebPages/WebForms/WebForm.cs index 90dcfce..94687a1 100644 --- a/Src/MvcPages/WebPages/WebForms/WebForm.cs +++ b/Src/MvcPages/WebPages/WebForms/WebForm.cs @@ -13,8 +13,8 @@ namespace Tellurium.MvcPages.WebPages.WebForms /// public class WebForm : PageFragment { - private readonly int numberOfSetRetries; - private readonly AfterFieldValueSet afterFieldValueSet; + private int numberOfSetRetries; + private AfterFieldValueSet afterFieldValueSet; private List SupportedInputs { get; set; } public WebForm(IWebElement webElement, RemoteWebDriver driver, List supportedInputs, int numberOfSetRetries, AfterFieldValueSet afterFieldValueSet = AfterFieldValueSet.Nothing) : base(driver, webElement) @@ -24,6 +24,18 @@ public WebForm(IWebElement webElement, RemoteWebDriver driver, List supportedInputs, int numberOfSetRetries, AfterFieldValueSet afterFieldValueSet = AfterFieldValueSet.Nothing) + { + this.numberOfSetRetries = numberOfSetRetries; + this.afterFieldValueSet = afterFieldValueSet; + SupportedInputs = supportedInputs; + base.Init(driver, webElement); + } + /// /// Set value for field indicated by field name ///