コード例 #1
0
        /// <summary>
        /// Gets the web driver.
        /// </summary>
        /// <param name="contextManager">The object container.</param>
        /// <param name="options">The options.</param>
        /// <returns>The webdrivercontext object.</returns>
        public static WebDriverContext GetWebDriver(IContextManager contextManager, IWritableOptions <ConfigurationParameters> options)
        {
            var objectContainer = contextManager?.TestThreadContext.Get <IObjectContainer>("objectContainer");
            WebDriverContext webDriverContext = null;

            if (objectContainer.IsRegistered <WebDriverContext>())
            {
                webDriverContext = objectContainer.Resolve <WebDriverContext>();
            }

            if (options?.Value.BrowsersConfiguration.Browser == Browser.ChromeAndroid9)
            {
                AppiumLocalService = AndroidWebDriver.CreateAppiumLocalService();
                AppiumLocalService.Start();
            }

            if (webDriverContext?.WebDriver == null)
            {
                if (!objectContainer.IsRegistered <WebDriverContext>())
                {
                    objectContainer.RegisterTypeAs <WebDriverContext, WebDriverContext>();
                }
                objectContainer.Resolve <WebDriverContext>().CreateWebDriver();
                webDriverContext = objectContainer.Resolve <WebDriverContext>();
            }

            return(webDriverContext);
        }
コード例 #2
0
ファイル: Page.cs プロジェクト: PWookey/QA-TestAutomation
        public static T Create <T>(WebDriverContext webDriverContext, string baseUrl, string url)
            where T : Page
        {
            var constructor = typeof(T).GetConstructors().Where(c =>
            {
                var pars = c.GetParameters();
                if (pars.Count() < 3)
                {
                    return(false);
                }
                if (pars[0].ParameterType != typeof(WebDriverContext))
                {
                    return(false);
                }
                if (pars[1].ParameterType != typeof(string))
                {
                    return(false);
                }
                if (pars[2].ParameterType != typeof(string))
                {
                    return(false);
                }
                return(true);
            }).SingleOrDefault();

            if (constructor == null)
            {
                throw new InvalidOperationException("Your page class must implement default page constructor");
            }
            return((T)constructor.Invoke(new object[] { webDriverContext, baseUrl, url }));
        }
コード例 #3
0
ファイル: Hooks.cs プロジェクト: azunjurwad/ATF
        public void IEDriver()
        {
            var webDriverContext = new WebDriverContext();

            webClient = webDriverContext.CreateIEDriver();
            objectContainer.RegisterInstanceAs <WebClient>(webClient);
            objectContainer.RegisterInstanceAs <IWebDriver>(webClient.internetExplorerDriver);
        }
コード例 #4
0
ファイル: Hooks.cs プロジェクト: azunjurwad/ATF
        public void FirefoxDriver()
        {
            var webDriverContext = new WebDriverContext();

            webClient = webDriverContext.CreateFirefixDriver();
            objectContainer.RegisterInstanceAs <WebClient>(webClient);
            objectContainer.RegisterInstanceAs <IWebDriver>(webClient.firefoxDriver);
        }
コード例 #5
0
ファイル: Hooks.cs プロジェクト: azunjurwad/ATF
        public void ChromeDriver()
        {
            var webDriverContext = new WebDriverContext();

            webClient = webDriverContext.CreateChromeDriver();
            objectContainer.RegisterInstanceAs <WebClient>(webClient);
            objectContainer.RegisterInstanceAs <IWebDriver>(webClient.chromeDriver);
        }
コード例 #6
0
        public void navigateToEbay()
        {
            Driver.driver = WebDriverContext.getInstance().getWebDriver();
            Driver.driver.Manage().Window.Maximize();
            LoginPage lp = new LoginPage();

            lp.navigate();
            //test
        }
コード例 #7
0
 public void LoggingLocalA()
 {
     //WebDriverContext.Navigate("login");
     WebDriverContext.GetInstance().Driver.Navigate().GoToUrl("http://youla-dev/login");
     PageHelper.WaitForMap(() => PageBase.Map.LoginTextBox);
     PageBase.FillAuthForm("local\\a", "a");
     PageBase.ClickLoginButton();
     PageHelper.WaitForMap(() => PageBase.Map.UserNameDiv);
     PageBase.Validate().UserNameIs("a");
 }
コード例 #8
0
 public void LoggingLocalB()
 {
     WebDriverContext.Navigate("login");
     PageHelper.WaitForMap(() => PageBase.Map.LoginTextBox);
     PageBase.FillAuthForm("local\\b", "b");
     PageBase.ClickRememberMeButton();
     PageBase.ClickLoginButton();
     PageHelper.WaitForMap(() => PageBase.Map.UserNameDiv);
     PageBase.Validate().UserNameIs("b");
 }
コード例 #9
0
 public void JustOpenVorwand()
 {
     for (int i = 1; i < 3; i++)
     {
         Random n    = new Random();
         int    nInt = n.Next(10849573, 12849573);
         WebDriverContext.Navigate("vorwand#/id=" + nInt);
         Thread.Sleep(3000);
     }
 }
コード例 #10
0
        public override void SetUp()
        {
            base.SetUp();
            if (WebDriverContext.HasInstance)
            {
                WebDriverContext.Current.Dispose();
            }

            WebDriverContext.ReadConfig();
            WebDriverContext = WebDriverContext.Current;
        }
コード例 #11
0
        public void OpenCLoseReOpenVorwand()
        {
            WebDriverContext.Navigate("vorwand#/id=12849551");
            PageHelper.WaitForMap(() => PageBase.Map.AppliedButton);
            PageBase.ClickAppliedButton();

            PageHelper.WaitForMap(() => PageBase.Map.ReopenButton);
            PageBase.ClickReopenButton();

            PageHelper.WaitForMap(() => PageBase.Map.ReopenApproveButton);
            PageBase.ClickReopenApproveButton();
        }
コード例 #12
0
        public void OpenNewTabVorwand()
        {
            for (int e = 1; e < 10; e++)
            {
                WebDriverContext.OpenNewTab();
            }

            for (int i = 1; i < 350; i++)
            {
                for (int tabNumber = 0; tabNumber < 10; tabNumber++)
                {
                    Random n    = new Random();
                    int    nInt = n.Next(10849573, 12849573);
                    WebDriverContext.SwitchTab(tabNumber);
                    WebDriverContext.Navigate("vorwand#/id=" + nInt);
                }
            }
        }
コード例 #13
0
ファイル: VSSeleniumTest.cs プロジェクト: NanaShenley/sel
        /// <summary>
        /// Initialises a unit test instance - typically called from TestCleanup, passing in the test context.
        /// </summary>
        public static void Cleanup(TestContext testContext)
        {
            var        placeToExec = TestDefaults.Default.MethodOfExecution;
            IWebDriver driver      = null;

            if (placeToExec.ToLower().Contains("local"))
            {
                gridManager.CloseSeleniumGrid();
            }
            else if (placeToExec.ToLower().Contains("remote"))
            {
                //driver = new RemoteCaps(instance, testContext).RunOnRemoteMachine();
            }
            WebDriverContext context = WebContext.GetThreadLocalContext();

            context.Driver.Quit();
            context.Result.StopWatch();
            Debug.WriteLine("Test {0} completed. {1}", testContext.TestName, context.Result.ToString());
        }
コード例 #14
0
ファイル: Page.cs プロジェクト: PWookey/QA-TestAutomation
        public Page(WebDriverContext webDriverContext, string baseUrl, string url)
            : base(webDriverContext)
        {
            if (String.IsNullOrEmpty(baseUrl))
            {
                throw new ArgumentException("baseUrl can't be null or empty", "baseUrl");
            }

            _baseUrl      = baseUrl;
            _url          = url;
            _pageElements = new Dictionary <Type, PageElement>();
            InitPageElementProperties();
            PageFactory.InitElements(WebDriver, this);
            foreach (var pageElement in _pageElements)
            {
                PageFactory.InitElements(WebDriver, pageElement);
            }

            Current = this;
        }
コード例 #15
0
        public void ChooseProject()
        {
            if (!PageBase.IsAuthorized)
            {
                var loginPage = new LoginPage();
                loginPage.FillAuthForm("local\\b", "b");
                loginPage.ClickLoginButton();
                PageHelper.WaitForMap(() => PageBase.Map.UserNameDiv);
                loginPage.Validate().UserNameIs("b");
            }
            WebDriverContext.Navigate("calendar#/calendar/");

            PageHelper.WaitForMap(() => PageBase.Map.DropDownProjectArrow);
            PageBase.ClickProjectDropDownToOpen();

            var chooseProject = PageBase.Map.OpenedDropDownProjectTextBox;

            PageHelper.WaitUntilVisible(() => chooseProject);

            chooseProject.Clear();
            chooseProject.Click();
            chooseProject.SendKeys("Москва");
            SendKeys.SendWait("{ENTER}");

            var desktopPage = new DesktopPage();

            desktopPage.ValidateProject().UserProjectIs(PageBase.Map.DropDownProject.Text);

            string [] amountLeftBefore = { PageBase.Map.TerritoriesLeftAmount.Text };

            PageBase.Map.CheckBoxTaskLeft.Click();
            PageBase.Map.TaskToSyncButton.Click();

            PageHelper.WaitForMap(() => PageBase.Map.CheckBoxTaskRight);
            PageBase.Map.InformationRefresher.Click();
            Thread.Sleep(2000);

            string[] amountLeftAfter = { PageBase.Map.TerritoriesLeftAmount.Text };
            Assert.AreNotEqual(amountLeftBefore, amountLeftAfter);
        }
コード例 #16
0
        /// <summary>
        /// Gets the webdrivercontext.
        /// </summary>
        /// <param name="objectContainer">The configuration parameters object.</param>
        /// <param name="configurationParameters">The object container object.</param>
        /// <returns>The webDrvierContext object.</returns>
        public static WebDriverContext GetWebDriver(IObjectContainer objectContainer, ConfigurationParameters configurationParameters)
        {
            if (configurationParameters.BrowsersConfiguration.Browser == Browser.ChromeAndroid9)
            {
                AppiumLocalService = AndroidWebDriver.CreateAppiumLocalService();
                AppiumLocalService.Start();
            }

            if (configurationParameters.BrowsersConfiguration.ReuseBrowser)
            {
                var webDriver = new WebDriverContext(configurationParameters);

                objectContainer.RegisterInstanceAs <WebDriverContext>(webDriver);
                return(webDriver);
            }
            else
            {
                var webDriverContext = new WebDriverContext(configurationParameters);
                objectContainer.RegisterInstanceAs <WebDriverContext>(webDriverContext);
                return(webDriverContext);
            }
        }
コード例 #17
0
        public static PageElement Create(Type t, WebDriverContext webDriverContext)
        {
            var constructor = t.GetConstructors().Where(c =>
            {
                var pars = c.GetParameters();
                if (pars.Count() != 1)
                {
                    return(false);
                }
                if (pars[0].ParameterType != typeof(WebDriverContext))
                {
                    return(false);
                }
                return(true);
            }).SingleOrDefault();

            if (constructor == null)
            {
                throw new InvalidOperationException("Your page class must implement default page constructor");
            }
            return((PageElement)constructor.Invoke(new object[] { webDriverContext }));
        }
コード例 #18
0
        protected void TakeScreenshot(WebDriverContext instance)
        {
            var cfg = DriverConfiguration.GetConfiguration();

            if (!cfg.TakeScreenshots)
            {
                return;
            }

            var testName = TestContext.CurrentContext.Test.Name;
            var invalids = Path.GetInvalidFileNameChars();

            testName = invalids.Aggregate(testName, (current, inv) => current.Replace(inv.ToString(), string.Empty));

            if (testName.Length > 200)
            {
                testName = testName.Substring(0, 200) + "...";
            }

            var path = Path.Combine(
                cfg.ScreenshotDir,
                testName);

            var di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                Directory.CreateDirectory(path);
            }

            path = Path.Combine(
                di.FullName,
                StartTime.ToString(DateFormat) + ".png");

            instance.TakeScreenshot().SaveAsFile(
                path,
                ImageFormat.Png);
        }
コード例 #19
0
ファイル: TestlistenerBase.cs プロジェクト: NanaShenley/sel
        public void SetUpAndStartBrowsers(TestMethodInstance instance, ITestResult result)
        {
            // Check the proxy settings
            Proxy useProxy = null;

            if (!string.IsNullOrEmpty(Configuration.ProxyOverride))
            {
                string proxy = Configuration.ProxyOverride;
                useProxy              = new Proxy();
                useProxy.HttpProxy    = proxy;
                useProxy.FtpProxy     = proxy;
                useProxy.SslProxy     = proxy;
                useProxy.IsAutoDetect = false;
                useProxy.Kind         = ProxyKind.Manual;
            }
            // Now set the browser capabilities/options
            DesiredCapabilities cap;
            var    browser     = instance.GetMetadata(WebContext.BrowserKey) as string;
            string userDataDir = instance.Attr.UserDataDir;

            if (browser.Equals("chrome"))
            {
                ChromeOptions options = new ChromeOptions();
                options.SetLoggingPreference(LogType.Browser, LogLevel.All);
                options.AddArgument("--incognito");
                options.AddArgument("--explicitly-allowed-ports=95");
                options.AddArgument("--lang=en-GB");
                options.AddArgument("--disable-popup-blocking");
                options.AddArgument("--disable-extensions");
                options.AddArgument("--enable-javascript");
                options.AddArgument("--disable-web-security");
                options.AddArgument("--disable-plugins");
                options.AddArgument("--start-maximized");
                options.AddArgument("--enable-logging");
                options.AddArgument("--allow-running-insecure-content");
                options.AddArgument("--javascript-harmony");
                if (userDataDir != null)
                {
                    options.AddArguments("--user-data-dir=" + userDataDir);
                }
                if (useProxy != null)
                {
                    options.Proxy = useProxy;
                }
                cap = options.ToCapabilities() as DesiredCapabilities;
            }
            else
            {
                // Please think carefully before changeing this
                //https://code.google.com/p/selenium/wiki/InternetExplorerDriver
                InternetExplorerOptions IEOptions = new InternetExplorerOptions();
                IEOptions.UsePerProcessProxy = true;
                if (useProxy != null)
                {
                    IEOptions.Proxy = useProxy;
                }
                cap = IEOptions.ToCapabilities() as DesiredCapabilities;
                //cap = DesiredCapabilities.InternetExplorer();
                cap.SetCapability("nativeEvents", true);
                cap.SetCapability("ignoreZoomSetting", true);
            }


            var domainuser = WindowsIdentity.GetCurrent() == null
                ? null
                : WindowsIdentity.GetCurrent().Name;

            char[] delimiterChars = { '\\' };
            var    words          = domainuser.Split(delimiterChars);
            var    user           = words[1];

            cap.SetCapability("user", user);
            cap.SetCapability("method", instance.ToString());
            IWebDriver driver = new RemoteWebDriver(Configuration.Hub, cap, Configuration.BrowserResponseTimeout);

            {
                WebDriverContext webDriverContext = new WebDriverContext(driver, instance, result,
                                                                         Configuration.Output);
                WebContext.Set(webDriverContext);
                instance.SetMetadata(WebContext.BrowserKey, browser);
            }

            driver.Manage().Window.Maximize();
        }
コード例 #20
0
#pragma warning restore CA1823,0169,0649
        #endregion WebElements

        /// <summary>
        /// Initializes a new instance of the <see cref="HomePage"/> class.
        /// </summary>
        /// <param name="webDriverContext">The web driver context.</param>
        public HomePage(WebDriverContext webDriverContext)
        {
            PageFactory.InitElements(webDriverContext.WebDriver, this);
        }
コード例 #21
0
 public TestStepDefinitions(ScenarioContext scenarioContext, WebDriverContext driverContext)
 {
     _scenarioContext = scenarioContext;
     _browser         = driverContext.driver;
 }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DragAndDropPage"/> class.
 /// </summary>
 /// <param name="webDriverContext">The web driver context.</param>
 public DragAndDropPage(WebDriverContext webDriverContext)
 {
     this.WebDriverContext = webDriverContext;
 }
コード例 #23
0
 public Hooks(WebDriverContext driverContext)
 {
     this.Driver = driverContext.driver;
 }
#pragma warning restore 0169, 0649
        #endregion webelements

        /// <summary>
        /// Initializes a new instance of the <see cref="WebElementsChecksPage1"/> class.
        /// </summary>
        /// <param name="webDriverContext">The web driver context.</param>
        public WebElementsChecksPage1(WebDriverContext webDriverContext)
        {
            PageFactory.InitElements(webDriverContext.WebDriver, this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WebElementColorsCheckPage"/> class.
 /// </summary>
 /// <param name="webDriverContext">The web driver context.</param>
 public WebElementColorsCheckPage(WebDriverContext webDriverContext)
 {
     this.WebDriverContext = webDriverContext;
 }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WebTablePage"/> class.
 /// </summary>
 /// <param name="webDriverContext">The web driver context.</param>
 public WebTablePage(WebDriverContext webDriverContext)
 {
     PageFactory.InitElements(webDriverContext.WebDriver, this);
     this.webTable = new WebTableHelper(this.webTableWebElement);
 }
コード例 #27
0
 protected PageElement(WebDriverContext webDriverContext)
 {
     WebDriverContext = webDriverContext;
 }
コード例 #28
0
        public IWebDriver RunOnRemoteMachine()
        {
            // TODO: Take this setting from TestContext
            Configuration.SystemUnderTest = TestDefaults.Default.DefaultSystemUnderTest;// Configuration.lab_five;

            Environment.Initialise(new WebContext(), new SeSettings(), new SeLogger());
            string className = testContext.FullyQualifiedTestClassName;
            string testName  = testContext.TestName;
            // NOTE: You might have to use AppDomain.CurrentDomain.GetAssemblies() and then call GetTypes on each assembly if this code
            //       resides in a baseclass in another assembly.
            Type       currentlyRunningClassType = instance.GetType().Assembly.GetTypes().FirstOrDefault(f => f.FullName == className);
            MethodInfo currentlyRunningMethod    = currentlyRunningClassType.GetMethod(testName);
            // Replace WorkItemAttribute with whatever your attribute is called...
            IEnumerable <WebDriverTestAttribute> webDriverAttributes = currentlyRunningMethod.GetCustomAttributes(typeof(WebDriverTestAttribute), true) as IEnumerable <WebDriverTestAttribute>;
            WebDriverTestAttribute webDriverAttr = webDriverAttributes.FirstOrDefault();
            string browserName = webDriverAttr.Browsers[0];

            if (String.IsNullOrEmpty(browserName))
            {
                if (webDriverAttr is ChromeUiTestAttribute)
                {
                    browserName = BrowserDefaults.Chrome;
                }
                else if (webDriverAttr is IeUiTestAttribute)
                {
                    browserName = BrowserDefaults.Ie;
                }
                //                else if (webDriverAttr is )
                //                    browserName = BrowserDefaults.Firefox;
                //                else if (webDriverAttr is )
                //                    browserName = BrowserDefaults.Firefox;
            }
            Assert.IsNotNull(browserName, "No browser name");

            // Set the user
            string domainuser = WindowsIdentity.GetCurrent() == null
                ? null
                : WindowsIdentity.GetCurrent().Name;

            char[] delimiterChars    = { '\\' };
            var    words             = domainuser.Split(delimiterChars);
            var    user              = words[1];
            DesiredCapabilities caps = null;

            BrowserManager manager = new BrowserManager(webDriverAttr);
            Proxy          proxy   = manager.CheckAndSetUpProxy();

            caps = manager.ChooseRequiredBrowser(caps, browserName, proxy);

            // Set common capabilities
            caps.SetCapability("user", user);
            caps.SetCapability("method", testName);
            //Set BrowserStack Details
            caps.SetCapability("os", BrowserStack.Default.OsName);            //eg. "Windows"
            caps.SetCapability("os_version", BrowserStack.Default.OsVersion); // eg. "7"
            caps.SetCapability("browser", BrowserStack.Default.BrowserName);
            caps.SetCapability("browser_version", BrowserStack.Default.BrowserVersion);
            caps.SetCapability("project", BrowserStack.Default.ProjectName);
            caps.SetCapability("resolution", BrowserStack.Default.ScreenResolution); //1280x1024
            caps.SetCapability("browserstack.user", BrowserStack.Default.BrowserStackUser);
            caps.SetCapability("browserstack.key", BrowserStack.Default.BrowserStackKey);
            caps.SetCapability("browserstack.debug", "true");
            caps.SetCapability("build", "EdwinSmokeTest");
            caps = this.SetExtraBrowserStackCaps(caps, browserName);
            // Create the test method instance
            TestMethodInstance testMethodInstance = new TestMethodInstance(webDriverAttr,
                                                                           new Dictionary <string, object>(), null, instance, currentlyRunningMethod);
            // And a result
            ITestResult result = new UnitTestResult(testMethodInstance);

            var        stackUrl = new Uri(BrowserStack.Default.BrowserStackHub);
            IWebDriver driver   = new RemoteWebDriver(stackUrl, caps, configuration.BrowserResponseTimeout);

            {
                WebDriverContext webDriverContext = new WebDriverContext(driver, testMethodInstance, result, configuration.Output);
                WebContext.Set(webDriverContext);
                testMethodInstance.SetMetadata(WebContext.BrowserKey, browserName);
            }
            return(driver);
        }
コード例 #29
0
 public ShopPage(WebDriverContext webDriverContext)
 {
     this.WebDriverContext = webDriverContext;
 }
コード例 #30
0
 public static T Create <T>(WebDriverContext webDriverContext)
     where T : PageElement
 {
     return((T)Create(typeof(T), webDriverContext));
 }