public static void Wait(int miliseconds, int maxTimeOutSeconds = 60)
 {
     var wait = new WebDriverWait(Driver, new TimeSpan(0, 0, 1, maxTimeOutSeconds));
     var delay = new TimeSpan(0, 0, 0, 0, miliseconds);
     var timestamp = DateTime.Now;
     wait.Until(webDriver => (DateTime.Now - timestamp) > delay);
 }
Example #2
0
 public string GetPageFilterList()
 {
     driver.SwitchTo().Frame(investigationFRAME);
     WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitsec));
     IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("#crmGrid_rta_systemuser_rta_inv_case_investigatorid_SavedNewQuerySelector>span")));
     return element.Text;
 }
Example #3
0
        public void ShouldMoveAvatar()
        {
            IWebDriver driver = Tools.CreateDriver();
            try
            {
                driver.Navigate().GoToUrl(
                    "http://localhost/projects/test-client/client.xhtml#FIVESTesting&OverrideServerPort=34837");
                Tools.Login(driver, "1", "");

                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                IJavaScriptExecutor jsExecutor = driver as IJavaScriptExecutor;

                // Wait for the FIVES.AvatarEntityGuid to become available.
                string avatarGuid = (string)wait.Until(d => jsExecutor.ExecuteScript("return FIVES.AvatarEntityGuid"));

                // Wait until avatar's transform element becomes available.
                IWebElement avatarTransform = wait.Until(d => d.FindElement(By.Id("transform-" + avatarGuid)));

                string startTranslation = avatarTransform.GetAttribute("translation");

                jsExecutor.ExecuteScript("$(document).trigger({type: 'keydown', which: 87, keyCode: 87})");

                // Wait until avatar starts to move.
                wait.Until(d => avatarTransform.GetAttribute("translation") != startTranslation);
            }
            finally
            {
                driver.Quit();
            }
        }
Example #4
0
 public static void NavigateToDraftFolder()
 {
     Console.WriteLine("Navigating to Draft folder...");
     driver.FindElement(By.XPath("//*[@id='b-nav_folders']/div/div[3]/a/span")).Click();
     wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
     wait.Until(d => d.FindElement(By.Id("b-letters")));
 }
        public static void LoginProfile()
        {
            BaseTest.BaseUrl = GooglePage.HomePageUrl;
            BaseTest.Setup(BaseTest.BaseUrl);

            WebDriverWait wait = new WebDriverWait(BaseTest.BaseDriver, TimeSpan.FromSeconds(5));
            wait.Until((d) => { return d.Title.StartsWith("Google"); });

            GooglePage.AreAllElementShown();

            // login btn
            GooglePage.LoginBtn.Click();
            // login page
            // Sign in - Google Accounts
            Thread.Sleep(1500);
            Assert.AreEqual("Вход – Google Профили", BaseTest.BaseDriver.Title);

            Assert.IsTrue(GooglePage.EmailInput.Displayed);
            GooglePage.EmailInput.Clear();
            GooglePage.EmailInput.SendKeys("testqaexam");
            Assert.IsTrue(GooglePage.PasswordInput.Displayed);
            GooglePage.PasswordInput.Clear();
            GooglePage.PasswordInput.SendKeys("TestPass");
            Assert.IsTrue(GooglePage.SigninBtn.Displayed);
            GooglePage.SigninBtn.Click();
            Thread.Sleep(1500);
        }
        public static void RunTest([NotNull] string url,
		                           [NotNull] string initialPageTitle,
		                           [CanBeNull] IEnumerable<Action<IWebDriver>> testSteps)
        {
            Console.WriteLine(url);

            var steps = new List<Action<IWebDriver>>
                            {
                                b => b.Navigate().GoToUrl(url),
                                b =>
                                    {
                                        if (!String.IsNullOrEmpty(initialPageTitle))
                                        {
                                            var wait = new WebDriverWait(b, TimeSpan.FromSeconds(30));
                                            wait.Until(x => b.Title.Equals(initialPageTitle));

                                            b.Title.ShouldBeEqualTo(initialPageTitle, "incorrect page title");
                                        }
                                    }
                            };
            if (testSteps != null)
            {
                steps.AddRange(testSteps);
            }

            var notification = _runner.PassesTest(steps) ?? new Notification();
            notification.Success.ShouldBeTrue(notification.ToString());
        }
Example #7
0
        public void TestSportsRu()
        {
            Console.WriteLine("Test started!");
            const string mailUrl = "https://10minutemail.net";
            const string sportsUrl = "https://sports.ru/";
            using (D)
            {
                D.Navigate().GoToUrl(mailUrl);

                var wait = new WebDriverWait(D, TimeSpan.FromSeconds(30));
                wait.Until(ExpectedConditions.ElementIsVisible(By.Id("fe_text")));

                D.FindElement(By.Id("fe_text")).Click();

                var email = D.FindElement(By.Id("fe_text")).GetAttribute("value");
                var username = email.Split('@').First();
                var password = "www12342";

                D.RegSportsRu(sportsUrl, email, password, username);
                
                D.Navigate().GoToUrl(mailUrl);

                Thread.Sleep(5000);
            }
        }
 public ScrollElement(ScrollerItems item)
 {
     ImageDropName = itemsdrop[item];
     ImageDragName = itemsdrag[item];
     locator = itempath[item];
     var wait = new WebDriverWait(Browser.GetDriver(), TimeSpan.FromMilliseconds(Convert.ToDouble(Configuration.GetTimeout())));
     try
     {
         wait.Until(waiting =>
         {
             try
             {
                 return Browser.GetDriver().FindElement(locator).GetAttribute("style").Contains("background-image: url");
             }
             catch (Exception)
             {
                 return false;
             }
         });
     }
     catch (WebDriverTimeoutException)
     {
         Assert.Fail("Cannot wait until image displayed");
     }
 }
Example #9
0
 public WebBlock(Session session) : base(session)
 {
     // Wait for the DOM to start changing so we can START waiting for the new element
     this.Pause(200);
     Wait = new WebDriverWait(Session.Driver, new TimeSpan(3000));
     Tag = Wait.Until(driver => driver.GetElement(By.TagName("body")));
 }
    public static IEnumerable<IWebElement> WaitUntilElementsPresent(this IWebDriver driver, By selector)
    {
      var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
      wait.Until(ExpectedConditions.ElementExists(selector));

      return driver.FindElements(selector);
    }
 public void ClickAddNewTenancyRequestButton()
 {
     RefreshPageFrame.RefreshPage(driver, frameId);
     this.driver.SwitchTo().Frame(FRAMETenancyRequest);
     WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitsec));
     wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("img[alt='Add New Tenancy Request']"))).Click();
 }
Example #12
0
        public void sumi()
        {
            IWebElement element;
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            // webpegeを表示
            driver.Navigate().GoToUrl("https://www.f-aspit.com/aspit/portal/login.asp");
            driver.FindElement(By.Name("KigyoCD")).SendKeys("99990005");
            driver.FindElement(By.Name("UserID")).SendKeys("goen9995");
            driver.FindElement(By.Name("Password")).SendKeys("354959");
            driver.FindElement(By.CssSelector("img[id='img01']")).Click();

            driver.SwitchTo().Frame("fraNews");
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
            wait.Until(ExpectedConditions.ElementToBeClickable(By.Name("btnMenu0")));
            element = driver.FindElement(By.Name("btnMenu0"));
            element.SendKeys(Keys.Enter);
            wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Name("btnMenu0")));
            wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt("main"));
            element = driver.FindElement(By.LinkText("受注照会"));
            element.SendKeys(Keys.Enter);
            driver.FindElement(By.Name("selFromDay")).Click();
            driver.FindElement(By.XPath("//span[@id='idTargetKikanArea_From_Day']/select//option[1]")).Click();
            driver.FindElement(By.Id("imgDownload")).Click();
            //ここにダウンロード処理を入れる
            driver.Quit();
        }
        public static void WaitForPageToLoad(this IWebDriver driver)
        {
            TimeSpan timeout = new TimeSpan(0, 0, 100);
            WebDriverWait wait = new WebDriverWait(driver, timeout);
            IJavaScriptExecutor javaScript = driver as IJavaScriptExecutor;
            if (javaScript == null)
                throw new ArgumentException("driver", "driver must support javascript execution");

            wait.Until((d) =>
            {
                try
                {
                    string readyState =
                        javaScript.ExecuteScript("if (document.readyState) return document.readystate;").ToString();
                    return readyState.ToLower() == "complete";
                }
                catch (InvalidOperationException e)
                {
                    //Window is no lonfer available
                    return e.Message.ToLower().Contains("unable to get browser");
                }
                catch (WebDriverException e)
                {
                    //Browser is no longer available
                    return e.Message.ToLower().Contains("unable to connect");
                }
                catch (Exception)
                {
                    return false;
                }
            });
        }
        public void SearchNotExistingBug()
        {
            BaseTest.BaseUrl = BugTrackerPage.HomePageUrl;
            BaseTest.Setup(BaseTest.BaseUrl);

            WebDriverWait wait = new WebDriverWait(BaseTest.BaseDriver, TimeSpan.FromSeconds(5));
            wait.Until((d) => { return d.Title.StartsWith("BugTracker"); });

            BugTrackerPage.AreAllElementShown();

            BugTrackerPage.BugIdTextInput.Clear();
            BugTrackerPage.BugIdTextInput.SendKeys("123abc");
            BugTrackerPage.GotoIdBtn.Click();

            try
            {
                Assert.IsTrue(BugTrackerPage.ErrorMsgLabel.Displayed);
            }
            catch (NoSuchElementException nsee)
            {
                Thread.Sleep(1500);
                Assert.IsTrue(BugTrackerPage.ErrorMsgLabel.Displayed);
            }

            string expectedErrMsg = "Error: Bug ID must be an integer.";
            Assert.AreEqual(expectedErrMsg, BugTrackerPage.ErrorMsgLabel.Text);

            BaseTest.TearDown();
        }
Example #15
0
        public void TestExplicitWait()
        {
            IWebDriver driver = new ChromeDriver(@"C:\ChromeDriver");
            driver.Navigate().GoToUrl("http://dl.dropbox.com/u/55228056/AjaxDemo.html");

            try
            {
             			    IWebElement page4button = driver.FindElement(By.LinkText("Page 4"));
             			    page4button.Click();

               WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
               IWebElement message = wait.Until<IWebElement>((d) =>
               {
                    return d.FindElement(By.Id("page4"));
               });

             			    Assert.IsTrue(message.Text.Contains("Nunc nibh tortor"));

             		    }
            catch (NoSuchElementException e)
            {
             			    Assert.Fail("Element not found!!");
             		    } finally {
             			    driver.Close();
             		    }
        }
        public void QuickSearch(QuickSearchType recordtype, string name)
        {
            var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(15));
            var qucikSearchArrow =
                wait.Until(
                    ExpectedConditions.ElementIsVisible(
                        By.XPath(".//span[contains(text(), 'Search For')]/following::td[2]/a")));
            qucikSearchArrow.Click();


            const string xPath = "//li[.='{0}']";
            var key = string.Format(xPath, recordtype);

            wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(15));
            var module = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(key)));
            module.Click();


            const string id = "ctl00_{0}_Input";
            var record = string.Format(id, QuickSearchInputBoxLibrary[recordtype]);

            wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(15));
            var recordnameinputbx = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(record)));
            recordnameinputbx.Click();
            recordnameinputbx.SendKeys(name);


            const string recordXpath = "//td/span[contains(text(), '{0}')]";
            var recordname = string.Format(recordXpath, name);


            wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(15));
            var selectindividual = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(recordname)));
            selectindividual.Click();
        }
        // This should be replaced for any given application; this isn't a one-size-fits-all sort of thing.
        public static IWebElement GetElementFromActivePage(this IWebDriver driver, string cssSelector, double timeoutSeconds = 20)
        {
            IWebElement element = null;
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSeconds));
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(WebDriverTimeoutException),typeof(UnhandledAlertException));
            try
            {
                element = wait.Until(drv =>
                {
                    try
                    {
                        return drv.FindElement(By.CssSelector(cssPrefix + cssSelector));
                    }
                    catch (NoSuchElementException ex)
                    {
                        return null;
                    }
                });
            }
            catch (WebDriverTimeoutException ex)
            {
                return null;
            }

            return element;
        }
 public ContentPage GoToWriteNewPostScreen()
 {
     var wait = new WebDriverWait(Browser.Current, TimeSpan.FromSeconds(10));
     var el = wait.Until(drv => drv.FindElement(By.ClassName("btn-header")));
     el.Click();
     return this;
 }
            /// <summary>
            /// Lookup a reference field value.
            /// </summary>
            /// <param name="driver"></param>
            /// <param name="by">A mechanism by which to find the desired reference field within the current document.</param>
            /// <param name="sendKeys">A property value of the current reference field.</param>
            public static void Lookup(this IWebDriver driver, By by, string sendKeys)
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

                IWebElement lookup = wait.Until(ExpectedConditions.ElementIsVisible(by));
                lookup.Click();

                string currentWindowHandle = driver.CurrentWindowHandle;
                string searchWindow = driver.WindowHandles.First(o => o != currentWindowHandle);
                driver.SwitchTo().Window(searchWindow);

                IWebElement searchFor = wait.Until(ExpectedConditions.ElementExists(By.ClassName("list_search_text")));
                searchFor.Click();
                searchFor.Clear();
                searchFor.SendKeys(sendKeys);

                var selects = driver.FindElements(By.ClassName("list_search_select"));
                IWebElement search = selects.First(o => o.GetAttribute("id").Contains("_select"));
                driver.SelectOption(search, "Name"); //"for text");

                wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("img[title='Go']"))).Click();

                IWebElement item = wait.Until(ExpectedConditions.ElementExists(By.LinkText(sendKeys)));

                item.Click();

                driver.SwitchTo().Window(currentWindowHandle);
                driver.SwitchTo().Frame("gsft_main");
            }
 public ContentPage PostBody(string body)
 {
     var wait = new WebDriverWait(Browser.Current, TimeSpan.FromSeconds(10));
     var el = wait.Until(drv => drv.FindElement(By.Id("editor")));
     el.SendKeys(body);
     return this;
 }
 public override void ensurePageLoaded()
 {
     var wait = new WebDriverWait(pageManager.driver, TimeSpan.FromSeconds(PageManager.WAITTIMEFORFINDELEMENT));
     wait.Until(d => d.FindElement(By.ClassName("b-common_context_menu-content")));
     //Ожидание пока табличка остановится
     waitForFixPosition(pageManager.driver.FindElement(By.ClassName("b-common_context_menu-content")));
 }
 public ContentPage PostTitle(string title)
 {
     var wait = new WebDriverWait(Browser.Current, TimeSpan.FromSeconds(10));
     var el = wait.Until(drv => drv.FindElement(By.Name("txtTitle")));
     el.SendKeys(title);
     return this;
 }
Example #23
0
 public static void NavigateToDraftFolderFromNewMessage()
 {
     Console.WriteLine("Navigating to Draft folder...");
     driver.FindElement(By.XPath("//*[@id='b-nav_folders']/div/div[3]/a/span")).Click();
     wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
     wait.Until(d => d.FindElement(By.XPath("//span[text() = 'Сохранено в ']")));
 }
 public ContentPage Publish()
 {
     var wait = new WebDriverWait(Browser.Current, TimeSpan.FromSeconds(10));
     var el = wait.Until(drv => drv.FindElement(By.PartialLinkText("Publish")));
     el.Click();
     return this;
 }
Example #25
0
        public void SimpleNavigationTest()
        {
            // Create a new instance of the Firefox driver.

            // Notice that the remainder of the code relies on the interface,
            // not the implementation.

            // Further note that other drivers (InternetExplorerDriver,
            // ChromeDriver, etc.) will require further configuration
            // before this example will work. See the wiki pages for the
            // individual drivers at http://code.google.com/p/selenium/wiki
            // for further information.
            IWebDriver driver = new FirefoxDriver();

            //Notice navigation is slightly different than the Java version
            //This is because 'get' is a keyword in C#
            driver.Navigate().GoToUrl("http://www.google.com/");

            // Find the text input element by its name
            IWebElement query = driver.FindElement(By.Name("q"));

            // Enter something to search for
            query.SendKeys("Cheese");

            // Now submit the form. WebDriver will find the form for us from the element
            query.Submit();

            // Google's search is rendered dynamically with JavaScript.
            // Wait for the page to load, timeout after 10 seconds
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });

            //Close the browser
            driver.Quit();
        }
Example #26
0
        private void 分析AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (var page in JianWrapper.GetJian().Pages)
            {
                var url = page.Url;

                foreach (var interest in page.Interests.Keys)
                {
                    var xpath = page.Interests[interest].Pattern;

                    WebDriverWrapper.GetDriver().Navigate().GoToUrl(url);

                    var wait = new WebDriverWait(WebDriverWrapper.GetDriver(), TimeSpan.FromSeconds(120));

                    try
                    {
                        wait.Until(d => FindElement(d, xpath));
                        var element = FindElement(WebDriverWrapper.GetDriver(), xpath);
                        page.Interests[interest].Value = element.Text;
                    }
                    catch (Exception)
                    {
                        page.Interests[interest].Value = "查找失败。(请重试或者在设置中修改特征字符)";
                    }
                }
            }

            WebDriverWrapper.Close();

            JianWrapper.GetJian().SaveToFile();
            ReloadSetting();

            MessageBox.Show("分析完毕。");
        }
        public Individual360Page()
        {
            var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
            wait.Until(ExpectedConditions.UrlContains("/app/console/individual/view?"));

            PageFactory.InitElements(Driver, this);
        }
Example #28
0
        public void should_open_gmail_and_send_message()
        {
            //arrange
            ChromeDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://www.google.com.ua");

            WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 20));

            //act && assert
            GetElementOnXPath(driver, wait, "//*[@id=\"gbwa\"]/div[1]/a").Click();
            GetElementOnXPath(driver, wait, "//*[@id=\"gb23\"]").Click();
            GetElementOnXPath(driver, wait, "//*[@id=\"gmail-sign-in\"]").Click();

            GetElementOnXPath(driver, wait, "//*[@id=\"Email\"]").SendKeys(login);
            GetElementOnXPath(driver, wait, "//*[@id=\"next\"]").Click();
            GetElementOnXPath(driver, wait, "//*[@id=\"Passwd\"]").SendKeys(pass);
            GetElementOnXPath(driver, wait, "//*[@id=\"signIn\"]").Click();

            GetElementOnXPath(driver, wait, "//*[@id=\":j2\"]/div/div").Click();
            GetElementOnXPath(driver, wait, "//*[@id=\":oi\"]").SendKeys("[email protected]");
            GetElementOnXPath(driver, wait, "//*[@id=\":o3\"]").SendKeys("testMsg");
            GetElementOnXPath(driver, wait, "//*[@id=\":p5\"]").SendKeys("Bu-ga-ga!!");
            GetElementOnXPath(driver, wait, "//*[@id=\":nt\"]").Click();

            string expectedText = "Повідомлення надіслано. Переглянути повідомлення";
            string actualText = GetElementOnXPath(driver, wait, "/html/body/div[7]/div[3]/div/div[1]/div[5]/div[1]/div[2]/div[3]/div/div/div[2]").Text;

            //Assert
            Assert.AreEqual(expectedText, actualText);
        }
Example #29
0
 public void BaseTestInitialize(IWebDriver initialDriver, string baseUri, int timeout)
 {
     this.Driver = initialDriver;
     this.BaseUri = baseUri;
     this.Timeout = timeout;
     this.Wait = new WebDriverWait(initialDriver, TimeSpan.FromSeconds(timeout));
 }
        public override void Execute(IWebDriver driver, dynamic context)
        {
            var resolvedSelector = Test.ResolveMacros(Selector);

            var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(Timeout == 0 ? 5000 : Timeout));

            try
            {
                if (WaitForVisible)
                {
                    wait.Until(d => ExpectedConditions.ElementIsVisible(By.CssSelector(resolvedSelector))(d));
                }
                else
                {
                    wait.Until(d => d.FindElement(By.CssSelector(resolvedSelector)));
                }
                if (IsFalseExpected)
                    throw new InvalidOperationException("Element with selector '" + Selector + "' exists.");
            }
            catch (WebDriverTimeoutException)
            {
                if (!IsFalseExpected)
                    throw;
            }
        }