public void InvocationTrows_Retry(Mock <IElementLocator> elementLocatorMock, Mock <IWebElement> webElementMock, ICollection <By> bys) { var counter = 0; elementLocatorMock.Setup(x => x.LocateElement(bys)) .Returns(webElementMock.Object); webElementMock.Setup(x => x.Click()) .Callback(() => { if (++counter == 3) { throw new StaleElementReferenceException(); } }); var proxy = WebElementProxy.Create(elementLocatorMock.Object, bys); proxy.Click(); proxy.Click(); elementLocatorMock.Verify(x => x.LocateElement(bys), Times.Once()); //Thrid call will cause a StaleElementReferenceException proxy.Click(); elementLocatorMock.Verify(x => x.LocateElement(bys), Times.Exactly(2)); }
public void InvocationTrows_Rethrows(Mock <IElementLocator> elementLocatorMock, Mock <IWebElement> webElementMock, ICollection <By> bys) { var counter = 0; elementLocatorMock.Setup(x => x.LocateElement(bys)) .Returns(webElementMock.Object); webElementMock.Setup(x => x.Click()) .Callback(() => { if (++counter >= 3) { throw new StaleElementReferenceException(); } }); var proxy = WebElementProxy.Create(elementLocatorMock.Object, bys); proxy.Click(); proxy.Click(); //Thrid (and higher) callcount will cause a StaleElementReferenceException Action action = () => proxy.Click(); action.Should().Throw <StaleElementReferenceException>(); }
private static object CreateProxyObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache) { object result = null; if (memberType == typeof(IList <IWebElement>)) { using (List <Type> .Enumerator enumerator = CustomPageObjectMemberDecorator.InterfacesToBeProxied.GetEnumerator()) { while (enumerator.MoveNext()) { Type current = enumerator.Current; Type type = typeof(IList <>).MakeGenericType(new Type[] { current }); if (type.Equals(memberType)) { result = WebElementListProxy.CreateProxy(memberType, locator, bys, cache); break; } } return(result); } } if (!(memberType == typeof(IWebElement))) { throw new ArgumentException("Type of member '" + memberType.Name + "' is not IWebElement or IList<IWebElement>"); } result = WebElementProxy.CreateProxy(CustomPageObjectMemberDecorator.InterfaceProxyType, locator, bys, cache); return(result); }
public void Caches(Mock <IElementLocator> elementLocatorMock, ICollection <By> bys) { var proxy = WebElementProxy.Create(elementLocatorMock.Object, bys); proxy.Click(); proxy.Click(); proxy.Click(); elementLocatorMock.Verify(x => x.LocateElement(bys), Times.Once()); }
private void ActivateSubMenus(WebElementProxy webElement) { //TODO: Try in multiple browsers //Try click first... //webElement.Get().Click(); //or this //HERE IS AN EXAMPLE OF USING A MOUSEOVER EVENT IN SELENIUM Actions action = new Actions(driver); action.MoveToElement(webElement.Get()).Click().Build().Perform(); }
public static IWebElement CreateWebElementProxy(WebElementDefinition element) { By elementBy = ConvertLocatorSearchMethodToBy(element.HowToSearch, element.Locator); bool shouldBecached = false; var driverParam = GetDriver(); var bysParam = new By[] { elementBy }; var elementProxy = new WebElementProxy(driverParam, bysParam, shouldBecached); return(elementProxy); }
public bool CreateObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache, [NotNullWhen(true)] out object?createdObject) { createdObject = null; if (memberType == typeof(IWebElement)) { createdObject = new WebElementProxy(locator, bys, cache); return(true); } return(false); }
public bool CreateObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache, [NotNullWhen(true)] out object?createdObject) { createdObject = null; if (typeof(IWrapsElement).IsAssignableFrom(memberType)) { var webElement = new WebElementProxy(locator, bys, cache); createdObject = WrapsElementFactory.Wrap(memberType, webElement); return(true); } return(false); }
private void InitializeElements() { pimsSupportMenu = new WebElementProxy(driver, By.LinkText("PIMS Support")); bondMenu = new WebElementProxy(driver, By.LinkText("Bond")); capsMenu = new WebElementProxy(driver, By.LinkText("CAPS")); cftMenu = new WebElementProxy(driver, By.LinkText("CFT")); icpiSetupMenu = new WebElementProxy(driver, By.LinkText("iCPI Setup")); lspdMenu = new WebElementProxy(driver, By.LinkText("LSPD")); pimsMenu = new WebElementProxy(driver, By.LinkText("PIMS")); securityMenu = new WebElementProxy(driver, By.LinkText("Security")); systemMaintenanceMenu = new WebElementProxy(driver, By.LinkText("System Maintenance")); dataStoreMenu = new WebElementProxy(driver, By.LinkText("Data Store")); logoutMenu = new WebElementProxy(driver, By.LinkText("Log off")); }
private object DecorateObject(MemberInfo member, IElementLocator locator) { FieldInfo field = member as FieldInfo; PropertyInfo property = member as PropertyInfo; if (field == null && (property == null || !property.CanWrite)) { return(null); } Type targetType = GetTargetType(member); IList <By> bys = CreateLocatorList(member); if (bys.Any()) { bool cache = DefaultPageObjectMemberDecoratorProxy.ShouldCacheLookup(member); object result; if (typeof(WebElement).IsAssignableFrom(targetType)) { var proxyElement = new WebElementProxy(typeof(IWebElement), locator, bys, cache); var args = new object[] { proxyElement, this._driver }; result = Activator.CreateInstance(targetType, args); } else if (typeof(IWebElement).IsAssignableFrom(targetType)) { result = new WebElementProxy(typeof(IWebElement), locator, bys, cache).GetTransparentProxy(); } else if (typeof(IList <WebElement>).IsAssignableFrom(targetType)) { throw new NotImplementedException(); //var proxyElements = new ProxyListElement(locator, bys, cache); //var args = new object[] { proxyElements, this._driver }; //result = Activator.CreateInstance(targetType, args); } else if (targetType == typeof(IList <IWebElement>)) { result = new WebElementListProxy(typeof(IList <IWebElement>), locator, bys, cache).GetTransparentProxy(); } else { throw new Exception($"Undefined type of element: '{targetType?.FullName}'"); } return(result); } return(null); }
private static object CreateProxyObject(Type memberType, string name, IElementLocator locator, IEnumerable <By> bys, string containerId, IReporter reporter) { object proxyObject = null; if (memberType == typeof(IWebElement)) { proxyObject = WebElementProxy.CreateProxy(InterfaceProxyType, locator, bys, name, containerId, reporter); } else if (memberType == typeof(IList <IWebElement>)) { proxyObject = WebElementListProxy.CreateProxy(memberType, locator, bys, name, containerId, reporter); } else { throw new ArgumentException("Type of member '" + memberType.Name + "' is not IWebElement or IList<IWebElement>."); } return(proxyObject); }
private static object CreateProxyObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache) { object proxyObject = null; if (memberType.GetInterfaces().FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection <>)) != null && typeof(Element).IsAssignableFrom(memberType.GetGenericArguments()[0])) { ReadOnlyCollection <IWebElement> elements = locator.LocateElements(bys); proxyObject = createListElements(memberType.GetGenericArguments()[0], memberType, elements); } else if (typeof(Element).IsAssignableFrom(memberType)) { IWebElement webElement = (IWebElement)WebElementProxy.CreateProxy(locator, bys, cache); Element element = (Element)memberType.GetConstructor(new[] { typeof(IWebElement) }).Invoke(new object[] { webElement }); PageFactory.InitElements(locator.SearchContext, element, new CustomFieldDecorator()); proxyObject = element; } else { throw new ArgumentException("Type of member '" + memberType.Name + "'Element or IList<Element>"); } return(proxyObject); }
void InitializeElements() { element1 = new WebElementProxy(driver, By.ClassName("blah")); }
void InitializeElements() { searchField = new WebElementProxy(driver, By.Name("q")); }
public WebElement(WebElementProxy webElementProxy, IWebDriver driver) : this(driver) { this.WebElementProxy = webElementProxy; }
private object DecorateWrappedWebElement(Type typeToDecorate, IElementLocator elementLocator, IEnumerable <By> bys) { var element = WebElementProxy.Create(elementLocator, bys); return(CreateAndPopulateWrapsElement(typeToDecorate, element)); }
private object DecorateWebElement(IElementLocator elementLocator, IEnumerable <By> bys) { return(WebElementProxy.Create(elementLocator, bys)); }
private void InitializeElements() { userName = new WebElementProxy(driver, By.Id("Email")); password = new WebElementProxy(driver, By.Id("Password")); }