示例#1
0
        public static T InitUiElements <T>(IUiElementLocator locator)
        {
            T page = default(T);

            Type            pageClassType = typeof(T);
            ConstructorInfo ctor          = pageClassType.GetConstructor(new Type[] { typeof(IBrowserDriver) });

            if (ctor == null)
            {
                throw new ArgumentException($"No constructor for the specified class containing a single argument of type {nameof(IBrowserDriver)} can be found");
            }

            if (locator == null)
            {
                throw new ArgumentNullException(nameof(locator), "locator cannot be null");
            }

            IBrowserDriver driver = locator.UiElementFinder as IBrowserDriver;

            if (driver == null)
            {
                throw new ArgumentException("The ui element finder of the locator must implement IBrowesDriver", nameof(locator));
            }

            page = (T)ctor.Invoke(new object[] { driver });

            InitUiElements(page, locator);
            return(page);
        }
 public TestPage1(IBrowserDriver driver)
     : base(driver)
 {
     InputField = driver.CreateTextField().FromID("TextField");
     OutputField = driver.CreateTextField().FromID("TextFieldOutput");
     Button = driver.CreateButton().FromID("UpdateButton");
 }
示例#3
0
        public static IBrowserDriver ValidationSummaryExists(this IBrowserDriver driver)
        {
            var count = (int)driver.EvaluateScript("$('div.validation-summary-errors').length");

            count.ShouldBe(1);
            return(driver);
        }
示例#4
0
        public static IBrowserDriver VerifyPage(this IBrowserDriver driver, string identifier)
        {
            var value = (string)driver.EvaluateScript("$('input[name=controller-action]').val()");

            value.ShouldBe(identifier);
            return(driver);
        }
 public void SetInput(IBrowserDriver browserDriver)
 {
     foreach (var selectText in _text)
     {
         browserDriver.SetValue(_baseName, selectText);
     }
     //  browserDriver.SetValue(_baseName+"_date",input.ToShortDateString()); - sets text field with string value
 }
		public void SetInput(IBrowserDriver browserDriver)
		{
			foreach (var selectText in _text)
			{
				browserDriver.SetValue(_baseName, selectText);
			}
			//  browserDriver.SetValue(_baseName+"_date",input.ToShortDateString()); - sets text field with string value
		}
 public void Setup()
 {
     const string rootUrl = "http://localhost:65488/";
     //var selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy", rootUrl);
     //selenium.Start();
     //_driver = new SeleniumDriver(selenium);
     _driver = new HtmlUnitDriver(rootUrl);
 }
示例#8
0
        public static IBrowserDriver VerifyPage <TController>(this IBrowserDriver driver, Expression <Func <TController, object> > pageExpression)
        {
            string controllerName         = typeof(TController).GetControllerName();
            string actionName             = pageExpression.GetActionName();
            string concatenatedIdentifier = controllerName + "." + actionName;

            return(VerifyPage(driver, concatenatedIdentifier));
        }
示例#9
0
        public void FixtureSetup()
        {
            string baseurl = ConfigurationManager.AppSettings["url"];

            _webBrowser = new WatinDriver(new IE(), baseurl);

            InputTesterFactory.Default         = () => new InputWrapperFactoryOverride();
            MultipleInputTesterFactory.Default = () => new MultipleInputFactoryOverride();
        }
示例#10
0
        public static IBrowserDriver AssertValue <TFormType>(this IBrowserDriver driver,
                                                             Expression <Func <TFormType, object> > expression,
                                                             string expectedValue)
        {
            string id    = ReflectionHelper.BuildNameFrom(expression);
            string value = driver.GetValue(id);

            value.ShouldBe(expectedValue);
            return(driver);
        }
示例#11
0
        public WebTestFixture(WebDriverConfig config)
        {
            var container = UnityContainerFactory.GetContainer();

            var resolver = container.Resolve <IElementResolver>(new ParameterOverride("resolver", container));

            _driver = container.Resolve <IBrowserDriver>(new ResolverOverride[]
            {
                new ParameterOverride("config", config),
                new ParameterOverride("resolver", resolver)
            });
        }
示例#12
0
        public ImplicitWaitScope(IBrowserDriver browser, Stack <TimeSpan> timeoutHistory, TimeSpan timeout, string message = null)
        {
            this.message        = message;
            this.browser        = browser;
            this.timeoutHistory = timeoutHistory;

            lock (timeoutHistory)
            {
                timeoutHistory.Push(timeout);
                browser.ChangeBrowserDriverTimeout(timeout);
                Log.Info(string.Format("ImplicitWaitScope: Set Timeout to {0}. {1}", timeout, message ?? string.Empty));
            }
        }
		public void SetInput(IBrowserDriver browserDriver)
		{
			var input = DateTime.Parse(_text);
			browserDriver.SetValue(_baseName+"_date",input.ToShortDateString());
			if (input.Hour == 0)
				browserDriver.SetValue(_baseName + "_hour", "12");
			else if (input.Hour > 12)
				browserDriver.SetValue(_baseName + "_hour", (input.Hour-12).ToString());
			else
				browserDriver.SetValue(_baseName + "_hour", input.Hour.ToString());

			browserDriver.SetValue(_baseName + "_minute", input.Minute.ToString());
			browserDriver.SetValue(_baseName + "_noon", input.Hour>=12?"P.M.":"A.M.");
			browserDriver.ExecuteScript("$('#" + _baseName + "_noon"+ "').blur();");
		}
示例#14
0
        public SimpleActionsFixture(IBrowserDriver browser)
        {
            _browser = browser;

            // SAMPLE:  InlineActions
            // Create a Sentence grammar inline that performs a simple action
            this["JustDoSomething"] = Do("I want to do something", () => Debug.WriteLine("I did something"));

            // Create a Sentence grammar inline that performs a simple action with a single input value
            // In this case, this sentence merely stores the value in a private field of this Fixture object
            this["CaptureNumber"] = Do <int>("Store the number {number}", number => _number = number);


            // Create a Sentence grammar inline that executes a lambda that has access to the ITestContext
            // in order to retrieve services and/or drivers or store information to the ITestContext
            this["OpenUrl"] = Do <string>("Open the browser to {url}", (url, c) =>
            {
                c.Retrieve <IBrowserDriver>().OpenUrl(url);
            });


            this["OpenUrl2"] = Do <string, IBrowserDriver>("Open the browser to {url}",
                                                           (url, driver) => driver.OpenUrl(url));


            this["SpecialAction"] = Do("Perform a special action", (step, context) =>
            {
                // Perform a special action of some sort with access
                // to both the current IStep and ITestContext
            });
            // END:  InlineActions

            this["ScriptedActions"] = Paragraph("Do a bunch of stuff", x =>
            {
                // Perform an action inside the Paragraph that is not part of the
                // Html output
                x += Do(() => doSomething());

                x += Do((step, context) =>
                {
                    // perform a silent action inside the Paragraph grammar
                });

                // Adds a grammar inline to this Paragraph
                x += Do("Open the home page", () => _browser.OpenUrl("http://localhost/application"));
            });
        }
        public SimpleActionsFixture(IBrowserDriver browser)
        {
            _browser = browser;

            // SAMPLE:  InlineActions
            // Create a Sentence grammar inline that performs a simple action
            this["JustDoSomething"] = Do("I want to do something", () => Debug.WriteLine("I did something"));

            // Create a Sentence grammar inline that performs a simple action with a single input value
            // In this case, this sentence merely stores the value in a private field of this Fixture object
            this["CaptureNumber"] = Do<int>("Store the number {number}", number => _number = number);

            // Create a Sentence grammar inline that executes a lambda that has access to the ITestContext
            // in order to retrieve services and/or drivers or store information to the ITestContext
            this["OpenUrl"] = Do<string>("Open the browser to {url}", (url, c) =>
            {
                c.Retrieve<IBrowserDriver>().OpenUrl(url);
            });

            this["OpenUrl2"] = Do<string, IBrowserDriver>("Open the browser to {url}",
                                                          (url, driver) => driver.OpenUrl(url));

            this["SpecialAction"] = Do("Perform a special action", (step, context) =>
            {
                // Perform a special action of some sort with access
                // to both the current IStep and ITestContext
            });
            // END:  InlineActions

            this["ScriptedActions"] = Paragraph("Do a bunch of stuff", x =>
            {
                // Perform an action inside the Paragraph that is not part of the
                // Html output
                x += Do(() => doSomething());

                x += Do((step, context) =>
                {
                    // perform a silent action inside the Paragraph grammar
                });

                // Adds a grammar inline to this Paragraph
                x += Do("Open the home page", () => _browser.OpenUrl("http://localhost/application"));
            });
        }
示例#16
0
        public Browser(IRuntimeServices runtimeServices, Settings configuration)
        {
            Trace.Write($"Configuration = {(configuration?.ToString() ?? "(null)")}");

            this.configuration = configuration ?? throw new MissingConfigurationException("Configuration is missing!");

            Log.Info("Initializing Driver...");
            var driverFactory = runtimeServices.GetBrowserFactoryBuilder(configuration);

            var browserName = this.configuration?.WebDriver?.Browser?.BrowserName.ToEnum <BrowserNames>();

            Log.Info($"WebDriver.BrowserDriver = {(browserName)}");
            browserDriver = driverFactory.Create(browserName ?? BrowserNames.chrome);

            if (configuration?.WebDriver?.Mode.ToEnum <Modes>() == Modes.browser)
            {
                var isMaximized = configuration?.WebDriver?.Browser?.Window?.IsMaximized ?? false;
                // configuring browser window
                Log.Info($"BrowserWindow.IsMaximized = {isMaximized}");

                if (isMaximized)
                {
                    MaximizePage();
                }
                else
                {
                    SetWindowSize(configuration?.WebDriver?.Browser?.Window?.InitialWidth ?? 800, configuration?.WebDriver?.Browser?.Window?.InitialHeight ?? 600);
                }
            }
            var  maxWait          = configuration?.WebDriver?.MaxWait;
            long waitMilliseconds = Math.Max(maxWait ?? 0, 60000L);

            Log.Info($"MaxWait = {waitMilliseconds}ms");
            var cfgMaxWait = TimeSpan.FromMilliseconds(waitMilliseconds);

            // set initial browser driver timeout to configuration or 1 minute if not defined
            lock (timeoutHistory)
            {
                timeoutHistory.Push(cfgMaxWait);
                browserDriver.ChangeBrowserDriverTimeout(cfgMaxWait);
            }

            FrameworkInit(runtimeServices);
        }
示例#17
0
        public Browser(Settings configuration)
        {
            this.configuration = configuration;

            var driverFactory = new SeleniumBrowserFactory(configuration);

            var browserName = configuration.WebDriver.BrowserDriver.ToEnum <BrowserNames>();

            browserDriver = driverFactory.Create(browserName);

            var cfgMaxWait = TimeSpan.FromMilliseconds(configuration.MaxWait == 0 ? 60000 : configuration.MaxWait);

            // set initial browser driver timeout to configuration or 1 minute if not defined
            lock (timeoutHistory)
            {
                timeoutHistory.Push(cfgMaxWait);
                browserDriver.ChangeBrowserDriverTimeout(cfgMaxWait);
            }
        }
        public void SetInput(IBrowserDriver browserDriver)
        {
            var input = DateTime.Parse(_text);

            browserDriver.SetValue(_baseName + "_date", input.ToShortDateString());
            if (input.Hour == 0)
            {
                browserDriver.SetValue(_baseName + "_hour", "12");
            }
            else if (input.Hour > 12)
            {
                browserDriver.SetValue(_baseName + "_hour", (input.Hour - 12).ToString());
            }
            else
            {
                browserDriver.SetValue(_baseName + "_hour", input.Hour.ToString());
            }

            browserDriver.SetValue(_baseName + "_minute", input.Minute.ToString());
            browserDriver.SetValue(_baseName + "_noon", input.Hour >= 12?"P.M.":"A.M.");
            browserDriver.ExecuteScript("$('#" + _baseName + "_noon" + "').blur();");
        }
示例#19
0
 public ProductPage(IBrowserDriver browserDriver) : base(browserDriver)
 {
 }
 public BasePageObject(IBrowserDriver browserDriver)
 {
     WebDriver = browserDriver.WebDriver;
 }
示例#21
0
 public override void SetInput(IBrowserDriver browserDriver)
 {
     browserDriver.SetValue(_inputName, _value);
 }
示例#22
0
 public abstract void SetInput(IBrowserDriver browserDriver);
示例#23
0
 public abstract void AssertInputValueMatches(IBrowserDriver browserDriver);
示例#24
0
 public InputForm(IBrowserDriver browserDriver, InputTesterFactoryRegistry factories)
 {
     _browserDriver = browserDriver;
     _factories     = factories;
     SubmitName     = "Submit";
 }
示例#25
0
 public override void SetInput(IBrowserDriver browserDriver)
 {
     //browserDriver.ExecuteScript(("tinyMCE.execInstanceCommand('" + _inputName + "', 'mceSetContent', false, '" +
     //                             _value + "')"));
 }
 public PageWithImages(IBrowserDriver driver)
     : base(driver)
 {
     ImageWithAbsolutePath = driver.CreateImage().FromID("imageWithAbsolutePath");
     ImageWithRelativePath = driver.CreateImage().FromID("imageWithRelativePath");
 }
示例#27
0
 public void teardown()
 {
     _webBrowser.Dispose();
     _webBrowser = null;
 }
示例#28
0
 public InputForm(IBrowserDriver browserDriver)
 {
     _browserDriver = browserDriver;
     SubmitName     = "Submit";
 }
示例#29
0
 public ListPage(IBrowserDriver driver)
     : base(driver)
 {
     Array = driver.CreateArray("//ul/li", x => new ListArray(x));
 }
示例#30
0
        public override void AssertInputValueMatches(IBrowserDriver browserDriver)
        {
            string actualValue = browserDriver.GetValue(_inputName);

            _value.ShouldEqual(actualValue, "Asserting value for input '" + _inputName + "'.");
        }
示例#31
0
        public static IBrowserDriver ValidationSummaryContainsMessageFor <TModelType>(this IBrowserDriver driver,
                                                                                      Expression
                                                                                      <Func <TModelType, object> >
                                                                                      expression)
        {
            string displayname    = new DefaultNameConvention().PropertyName(ReflectionHelper.FindPropertyFromExpression(expression));
            var    jquerySelector = string.Format(@"$('div.{0} ul li:contains(""{1}"")').text()", "validation-summary-errors", displayname);
            var    count          = (string)driver.EvaluateScript(jquerySelector);

            count.AssertStringContains(displayname);
            return(driver);
        }
 public Browser(IBrowserDriver browserDriver)
 {
     _instance = browserDriver;
 }
示例#33
0
 public override void AssertInputValueMatches(IBrowserDriver browserDriver)
 {
     throw new NotImplementedException();
 }
 public HomePageModel(IBrowserDriver driver)
 {
     _driver = driver;
 }
 public ActualControl(IBrowserDriver driver)
     : base(driver)
 {
     TextField = driver.CreateTextField().FromID("field");
 }
 public CookieTestPage(IBrowserDriver driver)
     : base(driver)
 {
     TextField = driver.CreateTextField().FromID("textField");
     Button = driver.CreateButton().FromID("submitButton");
 }
示例#37
0
 public Page(IBrowserDriver driver)
 {
     PageFactory.InitUiElements(this, new DefaultUiElementLocator(driver), new DefaultPageObjectDecorator());
 }
 public RedirectToPage1(IBrowserDriver driver)
     : base(driver)
 {
 }
示例#39
0
 public static ImplicitWaitScope Create(IBrowserDriver driver, Stack <TimeSpan> timeoutHistory, TimeSpan timeout, string message = null)
 {
     return(new ImplicitWaitScope(driver, timeoutHistory, timeout, message));
 }
示例#40
0
 public LoginPage(IBrowserDriver browserDriver) : base(browserDriver)
 {
 }
		public void AssertInputValueMatches(IBrowserDriver browserDriver)
		{
			throw new NotImplementedException();
		}
 public PageUsingUserControl(IBrowserDriver driver)
     : base(driver)
 {
     Control = new ActualControl(driver);
 }