public void Test1() { By by = By.CssSelector("a[ng-bind-html='caseName']"); var casesCount = driver.FindElements(by).Count; for (int i = 0; i < casesCount; i++) { var caseElement = driver.FindElements(by)[i]; var caseName = caseElement.Text; caseElement.Click(); waitForPage(); takeScreenShot(caseName); log.Info("****Case Name : " + caseName); if (driver.FindElements(By.Id("iframeContent")).Count > 0) { driver.SwitchTo().Frame("iframeContent"); var links = _driver.FindElements(By.CssSelector("#page a")); foreach (var link in links) { log.Info("Link Text[" + link.Text + "] HREF[" + link.GetAttribute("href") + "]"); } driver.SwitchTo().DefaultContent(); } driver.Navigate().GoToUrl(urlBase); } }
public void ShouldFilter() { // Fake backend with 2 phones NgMockE2EModule mockModule = new NgMockE2EModule(@" $httpBackend.whenGET('phones/phones.json').respond( [ { age: 12, carrier: 'AT&T', id: 'motorola-bravo-with-motoblur', imageUrl: 'img/phones/motorola-bravo-with-motoblur.0.jpg', name: 'MOTOROLA BRAVO\u2122 with MOTOBLUR\u2122', snippet: 'An experience to cheer about.' }, { age: 13, carrier: 'T-Mobile', id: 'motorola-defy-with-motoblur', imageUrl: 'img/phones/motorola-defy-with-motoblur.0.jpg', name: 'Motorola DEFY\u2122 with MOTOBLUR\u2122', snippet: 'Are you ready for everything life throws your way?' }, ] ); "); IWebDriver ngDriver = new NgWebDriver(driver, mockModule); ngDriver.Navigate().GoToUrl("http://angular.github.io/angular-phonecat/step-5/app/"); Assert.AreEqual(2, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count); ngDriver.FindElement(NgBy.Input("query")).SendKeys("bravo"); Assert.AreEqual(1, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count); ngDriver.FindElement(NgBy.Input("query")).SendKeys("!"); Assert.AreEqual(0, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count); }
public void ShouldFilter() { // Fake backend with 2 phones NgMockE2EModule mockModule = new NgMockE2EModule(@" $httpBackend.whenGET('phones/phones.json').respond( [ { age: 12, carrier: 'AT&T', id: 'motorola-bravo-with-motoblur', imageUrl: 'img/phones/motorola-bravo-with-motoblur.0.jpg', name: 'MOTOROLA BRAVO\u2122 with MOTOBLUR\u2122', snippet: 'An experience to cheer about.' }, { age: 13, carrier: 'T-Mobile', id: 'motorola-defy-with-motoblur', imageUrl: 'img/phones/motorola-defy-with-motoblur.0.jpg', name: 'Motorola DEFY\u2122 with MOTOBLUR\u2122', snippet: 'Are you ready for everything life throws your way?' }, ] ); "); IWebDriver ngDriver = new NgWebDriver(driver, mockModule); ngDriver.Navigate().GoToUrl("http://angular.github.io/angular-phonecat/step-5/app/"); Assert.AreEqual(2, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count); ngDriver.FindElement(NgBy.Model("query")).SendKeys("bravo"); Assert.AreEqual(1, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count); ngDriver.FindElement(NgBy.Model("query")).SendKeys("!"); Assert.AreEqual(0, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count); }
public void PerformNgByRepeaterAction() { driver.Navigate().GoToUrl(base_url); ngDriver.Url = driver.Url; ngDriver.FindElement(By.CssSelector("[ng-click='customer()']")).Click(); var ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); ng_customers[3].Click(); }
private IWebElement FindOneById(string id) { ReadOnlyCollection <NgWebElement> elements = driver.FindElements(By.Id(id)); Assert.AreEqual(1, elements.Count); return(elements[0]); }
public IList <NgWebElement> FindAllElements(By locator) { _log.Log($"Getting the list of elements by locator {locator} "); IList <NgWebElement> allElements = _ngDriver.FindElements(locator); return(allElements); }
public void ShouldListTodos() { ngDriver.Navigate().GoToUrl("http://www.angularjs.org"); var elements = ngDriver.FindElements(NgBy.Repeater("todo in todoList.todos")); Assert.AreEqual("build an angular app", elements[1].Text); Assert.AreEqual(false, elements[1].Evaluate("todo.done")); }
public void ShouldListTodos() { var ngDriver = new NgWebDriver(driver); ngDriver.Navigate().GoToUrl("http://www.angularjs.org"); var elements = ngDriver.FindElements(NgBy.Repeater("todo in todoList.todos")); Assert.AreEqual("build an angular app", elements[1].Text); Assert.AreEqual(false, elements[1].Evaluate("todo.done")); }
public ReviewPage(string url, NgWebDriver driver) { this.url = url; this.driver = driver; driver.Url = url; Entities = driver.FindElements(By.ClassName("inline-edit")).Select(i => new Entity(i)).ToList(); docTextContainer = driver.FindElement(By.ClassName("doc-text_container")); fullText = driver.FindElement(By.Id("full-text")); }
/// <summary> /// Evita a utilização de elementos obsoletos (que pertece a uma página que não está mais disponível) /// </summary> /// <param name="NgDriver">Driver utilizado</param> /// <param name="path">Critério para localizar os elementos</param> /// <returns></returns> public static IList <NgWebElement> AvoidStaleElements(this NgWebDriver NgDriver, By path) { while (true) { try { return(NgDriver.FindElements(path)); } catch (StaleElementReferenceException) { } } }
public void ShouldListTodos() { var ngDriver = new NgWebDriver(driver); ngDriver.Navigate().GoToUrl("http://www.angularjs.org"); var elements = ngDriver.FindElements(NgBy.Repeater("todo in todoList.todos")); Assert.AreEqual("build an AngularJS app", elements[1].Text.Trim()); Assert.AreEqual(false, elements[1].Evaluate("todo.done")); Thread.Sleep(5000); }
public void Given_I_have_entered_P0_into_the_search_bar(string city) { //Send city to search box and set active var search = _ngDriver.FindElement(By.XPath("//input[@name='search']")); search.SendKeys(city); search.Click(); _ngDriver.WaitForAngular(); //Verify Selected Element is Correct, if not select if (_ngDriver.FindElement(NgBy.Binding("getPresName($index)")).Text.ToLower() != city.ToLower()) { _ngDriver.FindElements(NgBy.Repeater("item in results | limitTo:10")). First(x => x.Text == city).Click(); } }
public void ShouldChangeSelectedtOption() { ReadOnlyCollection <NgWebElement> options = ngDriver.FindElements(NgBy.Repeater("option in options")); var options_enumerator = options.GetEnumerator(); options_enumerator.Reset(); while (options_enumerator.MoveNext()) { NgWebElement option = (NgWebElement)options_enumerator.Current; if (option.Text.Equals("two", StringComparison.Ordinal)) { option.Click(); } } NgWebElement element = ngDriver.FindElement(NgBy.SelectedOption("myChoice")); StringAssert.IsMatch("two", element.Text); }
public void TestMethod() { ObjectRepository.Driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(60); ObjectRepository.Driver.Navigate().GoToUrl("https://www.copaair.com/en/web/us"); var ngDriver = new NgWebDriver(ObjectRepository.Driver); var list = ngDriver.FindElements(NgBy.Repeater("item in desktopBookingTabs")); var element = list.First((x) => { return(x.Text.Contains("Manage your booking")); }); element.Click(); ngDriver.WaitForAngular(); ngDriver.FindElement(NgBy.Model("remoteSearchCriteria.travelerLastName")).SendKeys("Thisistest"); ngDriver.FindElement(NgBy.Model("bookingReference")).SendKeys("121421445252"); ngDriver.FindElement(By.Id("sendReservationForm")).Click(); Thread.Sleep(TimeSpan.FromSeconds(5)); }
public void ShouldSubstract() { #pragma warning disable 618 var first = ngDriver.FindElement(NgBy.Input("first")); #pragma warning restore 618 first.SendKeys("10"); #pragma warning disable 618 var second = ngDriver.FindElement(NgBy.Input("second")); #pragma warning restore 618 second.SendKeys("2"); ReadOnlyCollection <NgWebElement> ng_math_operators = ngDriver.FindElements(NgBy.Options("value for (key, value) in operators")); NgWebElement ng_substract_math_operator = ng_math_operators.First(op => op.Text.Equals("-", StringComparison.Ordinal)); Assert.IsNotNull(ng_substract_math_operator); ng_substract_math_operator.Click(); var goButton = ngDriver.FindElement(By.Id("gobutton")); goButton.Click(); NgWebElement result_element = ngDriver.FindElement(NgBy.Binding("latest")); Assert.AreEqual("8", result_element.Text); ngDriver.Highlight(result_element, 1000); }
public IList <NgWebElement> GetRelatedQueries() { return(_ngDriver.FindElements(RelatedQueriesXpath)); }
public IEnumerable <NgWebElement> ReturnElements(By by) { //_wait.Until(ExpectedConditions.ElementExists(by)); return(_ngDriver.FindElements(by)); }
public static void Main(string[] args) { IWebDriver driver = new ChromeDriver(); //sets timeouts, webdriver and goes to url driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(30); var ngDriver = new NgWebDriver(driver, "[ng-app = 'UiApp']"); ngDriver.Navigate().GoToUrl("http://www.glintinc.com/pulsepreview/"); //determines progress bar values and number of questions var progress = ngDriver.FindElement(By.ClassName("lightText")); var valueMax = progress.GetAttribute("aria-valuemax"); var valueNow = progress.GetAttribute("aria-valuenow"); var ctrNow = int.Parse(valueNow); var ctr = int.Parse(valueMax); Console.WriteLine("The number of questions in this quiz is " + valueMax); Console.WriteLine("The progress bar current value is " + valueNow); //clicks on initial button to go to questions var incrementer = ctr - 1; var nextPage = ngDriver.FindElement(By.ClassName("icon-nextquestion")); nextPage.Click(); Console.WriteLine("Initial blue arrow clicked, proceeding to questions"); //Answer questions loop for (int i = 0; i < ctr; i++) { //Check progress bar is incrementing var stopIndex = ctr - 1; var progressLoop = ngDriver.FindElement(By.ClassName("lightText")); var valueNowLoop = progress.GetAttribute("aria-valuenow"); Console.WriteLine("The progress bar current value is: " + valueNowLoop); //Click choice on question if (i == 0) { NgWebElement question = ngDriver.FindElements(NgBy.Model("answer.questionAnswerValue"))[1]; question.SendKeys("{ ENTER }"); Console.WriteLine("Answer Value Clicked for question"); } //Finds active question if (i > 0 && i < stopIndex) { new WebDriverWait(ngDriver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(NgBy.Repeater("question in section.activeQuestions"))); var questionResponse = ngDriver.FindElements(NgBy.Repeater("question in section.activeQuestions"))[i]; var elementGo = questionResponse.FindElements(NgBy.Model("answer.questionAnswerValue"))[i]; Console.WriteLine("Question Element Found for question index = " + i); if (elementGo != null) { //hover over and click add comments selection Actions builder = new Actions(ngDriver); var mouse = builder.MoveToElement(elementGo).Build(); mouse.Perform(); new WebDriverWait(ngDriver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementExists(By.ClassName("addComment"))); var commentBox = questionResponse.FindElement(By.ClassName("addComment")); var mouse1 = builder.MoveToElement(commentBox).Click().Build(); mouse1.Perform(); Console.WriteLine("Comment Clicked"); //adds comments new WebDriverWait(ngDriver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists(NgBy.Model("answer.questionAnswerComment"))); questionResponse.FindElement(NgBy.Model("answer.questionAnswerComment")).SendKeys("Test"); new WebDriverWait(ngDriver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists(By.XPath(".//*[contains(text(),'Save')]"))); new WebDriverWait(ngDriver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementToBeClickable(questionResponse.FindElement(By.XPath(".//*[contains(text(),'Save')]")))); questionResponse.FindElement(By.XPath(".//*[contains(text(),'Save')]")).Click(); Console.WriteLine("Comment submitted"); } } //finds last question if (i == stopIndex) { //Puts comments in last questions NgWebElement questionComment = ngDriver.FindElements(NgBy.Repeater("question in section.activeQuestions"))[i]; questionComment.FindElement(NgBy.Model("answer.questionAnswerComment")).SendKeys("Look at this!"); Console.WriteLine("Comment added"); //Saves final comments new WebDriverWait(ngDriver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementToBeClickable(questionComment.FindElement(By.XPath(".//*[contains(text(),'Save')]")))); questionComment.FindElement(By.XPath(".//*[contains(text(),'Save')]")).Click(); Console.WriteLine("Comment submitted"); } } //Click final submit button new WebDriverWait(ngDriver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementExists(By.ClassName("submitBtnOuter"))); var submitFinal = ngDriver.FindElement(By.ClassName("submitBtnOuter")); submitFinal.Click(); var progressFinal = ngDriver.FindElement(By.ClassName("lightText")); var valueNowFinal = progress.GetAttribute("aria-valuenow"); Console.WriteLine("The progress bar final value is: " + valueNowFinal); }
public IWebElement AddNewItem(string itemText) { _driver.FindElement(NgBy.Model("newTodo")).SendKeys(itemText + Keys.Enter); return(_driver.FindElements(NgBy.Repeater("todo in todos")).FirstOrDefault(x => x.Text == itemText)); }
protected ReadOnlyCollection <NgWebElement> FindElements(By by) { return(ngWebDriver.FindElements(by)); }
// see: https://automated-testing.info/t/c-problema-s-poiskom-elementa-i-ozhidaniem/22644/15 // NOTE: 'Protractor.NgBy': static types cannot be used as parameters (CS0721) public NgWebElement NgFindVisibleElement(/* this NgWebDriver ngDriver, */ By by, int custom_timeout_seconds) { int attempt = 0; // optional: // wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException), typeof(NoSuchElementException)); while (attempt * wait_seconds <= (int)(custom_timeout_seconds * 1000)) { try { // Exist: // wait.Until(d => ngDriver.FindElements(by).Any()); // Visible: // wait.Until(d => ngDriver.FindElements(by).Any(e => e.Displayed)== true) // Clickable: // wait.Until(d => ngDriver.FindElements(by).Any(e => e.Displayed && e.Enabled)== true) wait.Until(d => ngDriver.FindElements(by).Any(o => o.Displayed) == true); // System.InvalidOperationException : Sequence contains no matching element // OpenQA.Selenium.WebDriverTimeoutException: Timed out after 3 seconds } catch (Exception e) { if (attempt * wait_seconds >= (int)(custom_timeout_seconds * 1000)) { throw e; } else { Console.WriteLine(String.Format("Attempt # {0} to slurp exception: {1}", attempt, e.Message)); attempt++; Thread.Sleep(retry_delay); continue; } } break; } return(ngDriver.FindElements(by).First(o => o.Displayed)); }
public int GetOrdersCount() { return(ngDriver.FindElements(NgBy.Repeater("order in customer.orders")).Count); }
public void ShouldFindAllBindings() { Common.GetLocalHostPageContent("ng_directive_binding.htm"); IWebElement container = ngDriver.FindElement(By.CssSelector("body div")); Console.Error.WriteLine(container.GetAttribute("innerHTML")); ReadOnlyCollection <NgWebElement> elements = ngDriver.FindElements(NgBy.Binding("name")); Assert.AreEqual(5, elements.Count); foreach (NgWebElement element in elements) { Console.Error.WriteLine(element.GetAttribute("outerHTML")); Console.Error.WriteLine(String.Format("Identity: {0}", element.IdentityOf())); Console.Error.WriteLine(String.Format("Text: {0}", element.Text)); } }