public static PageObject GenerateWrappedPageObject(Type pageObjectType, PassengerConfiguration driver) { var wrappedProxy = Generate(pageObjectType, driver); var typePageObjectOfT = typeof(PageObject <>).MakeGenericType(pageObjectType); return((PageObject)Activator.CreateInstance(typePageObjectOfT, driver, wrappedProxy)); }
public void SetUp() { _config = new PassengerConfiguration { Driver = new FakeWebDriver() }; _po = new PageObject <FakePage>(_config); }
public PageObjectProxy(PassengerConfiguration configuration) { _configuration = configuration; _typeSubstitution = new TypeSubstitutionHandler(configuration); _elementSelectionHandler = new ElementSelectionHandler(configuration); _postProcessor = new ReturnValuePostProcessor(configuration); }
public void Setup() { _testConfig = new PassengerConfiguration { WebRoot = "http://www.davidwhitney.co.uk" }.WithDriver(new PhantomJSDriver()); }
public void Ctor_DefaultConfiguration_HasUrlVerificationStrategyOfStringContainingStrategy() { var config = new PassengerConfiguration(); Assert.That(config.UrlVerificationStrategies[0], Is.TypeOf <RegexStrategy>()); Assert.That(config.UrlVerificationStrategies[1], Is.TypeOf <StringContainingStrategy>()); }
public void WithDriver__GivenDriver_AssignsDriver() { var driver = (PhantomJSDriver) System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(typeof (PhantomJSDriver)); // Sorry mom var cfg = new PassengerConfiguration().WithDriver(driver); Assert.That(cfg.Driver, Is.InstanceOf<WebDriverBindings>()); }
public void UrlVerificationStrategiesStrategyFor_GivenPlainTextUrlAttribute_ReturnsStringContainingStrategy() { var discoveredUrl = new DiscoveredUrl(new Uri("http://tempuri.org"), new UriAttribute("http://tempuri.org", null)); var strat = new PassengerConfiguration().UrlVerificationStrategies.StrategyFor(discoveredUrl); Assert.That(strat, Is.TypeOf <StringContainingStrategy>()); }
public void WithDriver__GivenDriver_AssignsDriver() { var driver = (ChromeDriver)System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(typeof(ChromeDriver)); // Sorry mom var cfg = new PassengerConfiguration().WithDriver(driver); Assert.That(cfg.Driver, Is.InstanceOf <WebDriverBindings>()); }
public void UrlVerificationStrategiesStrategyFor_GivenUrlAttributeWithRegexPattern_ReturnsRegexStrategy() { var discoveredUrl = new DiscoveredUrl(new Uri("http://tempuri.org"), new UriAttribute("http://tempuri.org", "http://tempuri.org/[a-z]+")); var strat = new PassengerConfiguration().UrlVerificationStrategies.StrategyFor(discoveredUrl); Assert.That(strat, Is.TypeOf <RegexStrategy>()); }
public static object Generate(Type propertyType, PassengerConfiguration configuration) { if (propertyType == null) { throw new ArgumentNullException(nameof(propertyType)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } return(new Castle.DynamicProxy.ProxyGenerator().CreateClassProxy(propertyType, new PageObjectProxy(configuration))); }
public void Setup() { var chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--headless"); chromeOptions.AddArgument("--no-sandbox"); chromeOptions.AddArgument("window-size=1400,2100"); var driver = new ChromeDriver(Environment.CurrentDirectory, chromeOptions); _testConfig = new PassengerConfiguration { WebRoot = "http://www.davidwhitney.co.uk" }.WithDriver(driver); }
public void Setup() { _someDivPropertyInfo = typeof(SelectionTestClass).GetProperty("SomeDiv"); _idAttribute = _someDivPropertyInfo.GetCustomAttribute <IdAttribute>(); _navHandlers = new List <DriverBindings.IHandle>(); _mockDriver = new Mock <IDriverBindings>(); _mockDriver.Setup(x => x.NavigationHandlers).Returns(_navHandlers); var cfg = new PassengerConfiguration { Driver = _mockDriver.Object }; _handler = new ElementSelectionHandler(cfg); }
public void SomethingElse() { var testConfig = new PassengerConfiguration { WebRoot = "http://www.amazon.co.uk" }.WithDriver(new PhantomJSDriver()); using (var context = testConfig.StartTestAt<Homepage>()) { context .Page<Homepage>() .SearchFor("Game of thrones") .SearchResultSomething(); } }
public void WithPassenger() { var testConfig = new PassengerConfiguration { WebRoot = "http://www.amazon.co.uk" }.WithDriver(new PhantomJSDriver()); using (var context = testConfig.StartTestAt<Homepage>()) { context.Page<Homepage>().SearchFor("Game of thrones"); var ex = context.Page<SearchResultsPage>().AllH2s.Where(x => x.Text == "Game of Thrones - Season 4"); Assert.That(ex, Is.Not.Null); } }
public void SomethingElse() { var testConfig = new PassengerConfiguration { WebRoot = "http://www.amazon.co.uk" }.WithDriver(driver); using (var context = testConfig.StartTestAt <Homepage>()) { context .Page <Homepage>() .SearchFor("Game of thrones") .SearchResultSomething(); } }
public void WithPassenger() { var testConfig = new PassengerConfiguration { WebRoot = "http://www.amazon.co.uk" }.WithDriver(driver); using (var context = testConfig.StartTestAt <Homepage>()) { context.Page <Homepage>().SearchFor("Game of thrones"); var ex = context.Page <SearchResultsPage>().AllH2s.Where(x => x.Text == "Game of Thrones - Season 4"); Assert.That(ex, Is.Not.Null); } }
public static object ReturnOrMap(object sourceElement, Type targetType, PassengerConfiguration cfg) { if (sourceElement == null) { return(null); } if (sourceElement.GetType().IsAWebElement() && targetType.IsAPassengerElement()) { return(WrapIntoPassengerElement(sourceElement, targetType)); } if (sourceElement.GetType().IsCollection() && targetType.IsCollection()) { return(BuildCollectionOfWrappers(sourceElement, targetType, cfg)); } return(sourceElement); }
public DiscoveredUrl UrlFor(object classProxy, PassengerConfiguration configuration) { var attr = classProxy.GetType().GetCustomAttribute <UriAttribute>(); if (attr == null) { throw new Exception("Cannot navigate to a PageObject Object that doesn't have a [Uri(\"http://tempuri.org\")] attribute."); } if (attr.Uri.IsAbsoluteUri) { return(new DiscoveredUrl(attr.Uri, attr)); } if (string.IsNullOrWhiteSpace(configuration.WebRoot)) { throw new Exception("You need to configure a WebRoot to use relative Uris"); } return(new DiscoveredUrl(new Uri(new Uri(configuration.WebRoot), attr.Uri), attr)); }
public void Setup() { // It's hard to hand construct a proxy - so we'll go via the proxy generator. _fakeDriver = new Mock <IDriverBindings>(); _fakeDriver.Setup(x => x.Substitutes).Returns(new List <DriverBindings.TypeSubstitution> { new DriverBindings.TypeSubstitution(typeof(InterceptedType.SubbedType), () => new InterceptedType.SubbedType { Val = "Hi" }) }); _fakeDriver.Setup(x => x.NavigationHandlers).Returns(new List <DriverBindings.IHandle> { new DriverBindings.Handle <IdAttribute>((s, d) => "an id string"), new DriverBindings.Handle <LinkTextAttribute>((s, d) => "a text string"), new DriverBindings.Handle <CssSelectorAttribute>((s, d) => new FakeWebElement(s)) }); _cfg = new PassengerConfiguration { Driver = _fakeDriver.Object }; _proxy = ProxyGenerator.Generate <InterceptedType>(_cfg); }
public static IEnumerable BuildCollectionOfWrappers(object sourceElement, Type targetType, PassengerConfiguration configuration) { var elementType = targetType.GetElementItemType(); var wrappedItems = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)); foreach (var item in (IEnumerable)sourceElement) { var itemToAdd = CreateWrappedOrProxiedItem(item, elementType, configuration); wrappedItems.Add(itemToAdd); } if (targetType.IsArray) { return(wrappedItems.ToArray(elementType)); } var enumerableOfElementType = typeof(IEnumerable <>).MakeGenericType(elementType); if (targetType.Implements(enumerableOfElementType) || targetType == enumerableOfElementType) { return(wrappedItems); } return((IEnumerable)Activator.CreateInstance(targetType, wrappedItems)); }
public void Setup() { _fakeDriver = new PassengerConfiguration { Driver = new Mock <IDriverBindings>().Object }; }
public ElementSelectionHandler(PassengerConfiguration configuration) { _driver = configuration.Driver; }
public TypeSubstitutionHandler(PassengerConfiguration cfg) { _cfg = cfg; }
public object PostProcessReturnValue(object current, PropertySelectionContext ctx, PassengerConfiguration configuration) { if (current == null) { return(null); } var snapshotOfCollection = new List <object>(); if (current.IsCollection()) { snapshotOfCollection.AddRange(((IEnumerable)current).Cast <object>()); } if (!ctx.IsPageComponent) { if (ctx.RawSelectedElement.IsAWebElement() && ctx.TargetProperty.PropertyType.IsAPassengerElement()) { current = TypeMapping.WrapIntoPassengerElement(ctx.RawSelectedElement, ctx.TargetProperty.PropertyType); } if (ctx.RawSelectedElement.IsCollection() && ctx.TargetProperty.PropertyType.IsCollection()) { current = TypeMapping.BuildCollectionOfWrappers(ctx.RawSelectedElement, ctx.TargetProperty.PropertyType, _configuration); } } if (current.IsAPassengerElement()) { ((IPassengerElement)current).Inner = ctx.RawSelectedElement as IWebElement; } if (current.IsCollection()) { MapSnapshotToInnerProperty(current, snapshotOfCollection); } return(current); }
public void SetUp() { _cfg = new PassengerConfiguration(); _pp = new ReturnValuePostProcessor(_cfg); }
public void Setup() { _someDivPropertyInfo = typeof (SelectionTestClass).GetProperty("SomeDiv"); _idAttribute = _someDivPropertyInfo.GetCustomAttribute<IdAttribute>(); _navHandlers = new List<DriverBindings.IHandle>(); _mockDriver = new Mock<IDriverBindings>(); _mockDriver.Setup(x => x.NavigationHandlers).Returns(_navHandlers); var cfg = new PassengerConfiguration { Driver = _mockDriver.Object }; _handler = new ElementSelectionHandler(cfg); }
public static PassengerConfiguration WithDriver(this PassengerConfiguration cfg, OpenQA.Selenium.Remote.RemoteWebDriver driver) { cfg.Driver = new WebDriverBindings(driver); return(cfg); }
private static object CreateWrappedOrProxiedItem(object sourceItem, Type ofType, PassengerConfiguration configuration) { var itemToAdd = sourceItem; if (ofType.IsAPassengerElement()) { itemToAdd = WrapIntoPassengerElement(sourceItem, ofType); } if (ofType.IsPageComponent()) { itemToAdd = ProxyGenerator.Generate(ofType, configuration); } return(itemToAdd); }
public void Setup() { _fakeDriver = new PassengerConfiguration {Driver = new Mock<IDriverBindings>().Object}; }
public ReturnValuePostProcessor(PassengerConfiguration configuration) { _configuration = configuration; }
public void Setup() { // It's hard to hand construct a proxy - so we'll go via the proxy generator. _fakeDriver = new Mock<IDriverBindings>(); _fakeDriver.Setup(x => x.Substitutes).Returns(new List<DriverBindings.TypeSubstitution> { new DriverBindings.TypeSubstitution(typeof (InterceptedType.SubbedType), () => new InterceptedType.SubbedType {Val = "Hi"}) }); _fakeDriver.Setup(x => x.NavigationHandlers).Returns(new List<DriverBindings.IHandle> { new DriverBindings.Handle<IdAttribute>((s, d) => "an id string"), new DriverBindings.Handle<LinkTextAttribute>((s, d) => "a text string") }); var cfg = new PassengerConfiguration { Driver = _fakeDriver.Object }; _proxy = ProxyGenerator.Generate<InterceptedType>(cfg); }
public static TPageObjectType Generate <TPageObjectType>(PassengerConfiguration configuration) where TPageObjectType : class { return((TPageObjectType)Generate(typeof(TPageObjectType), configuration)); }