public void Back() { var MRes = new ManualResetEventSlim(true); MRes.Reset(); Exception exception = null; Task.Run(async() => { try { await navigation.Back().ConfigureAwait(false); await Task.Delay(50).ConfigureAwait(false); } catch (Exception ex) { exception = ex; } MRes.Set(); } ); MRes.Wait(); if (exception != null) { throw exception; } }
public void Back() { navigation.Back(); upDriver.WaitForDocumentState(); upDriver.WaitForjQuery(); upDriver.WaitForAngular(); }
public void GeneralTestingBaidu() { string actualTitle = string.Empty; if (!usingDriver) { try { //测试主页被打开 selenium.Start(); selenium.WindowMaximize(); selenium.Open("/"); actualTitle = selenium.GetTitle(); StringAssert.Equals(actualTitle, "百度一下,你就知道"); //测试糯米链接 selenium.Click("link=糯米"); selenium.WaitForPageToLoad("30000"); actualTitle = selenium.GetTitle(); StringAssert.Equals(actualTitle, "【上海团购】上海团购网站,高品质团购网站-百度糯米"); selenium.Open("/"); //测试新闻链接 selenium.Click("link=新闻"); selenium.WaitForPageToLoad("30000"); actualTitle = selenium.GetTitle(); StringAssert.Equals(actualTitle, "百度新闻搜索——全球最大的中文新闻平台"); selenium.GoBack(); //测试登陆 selenium.Click("link=登录"); //if (!selenium.IsTextPresent("登录百度账号")) //{ // Assert.Fail(); //} selenium.Type("id=TANGRAM__PSP_8__userName", "13764393095"); selenium.Type("id=TANGRAM__PSP_8__password", "edGomvS1"); selenium.Click("id=TANGRAM__PSP_8__submit"); selenium.WaitForPageToLoad("30000"); //if (selenium.IsTextPresent("密码错误")) //{ // Assert.Fail(); //} selenium.Click("link=退出"); selenium.Click("link=确定"); selenium.WaitForPageToLoad("30000"); //测试搜索 selenium.Type("kw", "Selenium"); selenium.Click("su"); selenium.WaitForPageToLoad("30000"); Assert.IsTrue(selenium.IsTextPresent("硒")); } catch (Exception e) { } finally { selenium.Close(); selenium.Stop(); } } else { try { //测试主页被打开 driver.Manage().Window.Maximize(); navigation = driver.Navigate(); navigation.GoToUrl(tagetURL); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); actualTitle = driver.Title; StringAssert.Equals(actualTitle, "百度一下,你就知道"); //测试糯米链接 driver.FindElementByLinkText("糯米").Click(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); actualTitle = driver.Title; StringAssert.Equals(actualTitle, "【上海团购】上海团购网站,高品质团购网站-百度糯米"); navigation.Back(); //测试新闻链接 driver.FindElementByLinkText("新闻").Click(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); actualTitle = driver.Title; StringAssert.Equals(actualTitle, "百度新闻搜索——全球最大的中文新闻平台"); navigation.Back(); //测试登陆 driver.FindElementByLinkText("登录").Click(); //if (!selenium.IsTextPresent("登录百度账号")) //{ // Assert.Fail(); //} IWebElement webElement = driver.FindElementById("TANGRAM__PSP_8__userName"); webElement.SendKeys("13764393095"); webElement = driver.FindElementById("TANGRAM__PSP_8__password"); webElement.SendKeys("edGomvS1"); driver.FindElementById("TANGRAM__PSP_8__submit").Click(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); //if (selenium.IsTextPresent("密码错误")) //{ // Assert.Fail(); //} Actions mouseMove = new Actions(driver); webElement = driver.FindElementByClassName("user-name"); mouseMove.MoveToElement(webElement); mouseMove.Perform(); webElement = driver.FindElementByClassName("quit"); webElement.Click(); driver.FindElementByLinkText("确定").Click(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); //测试搜索 webElement = driver.FindElementById("kw"); webElement.SendKeys("Selenium"); driver.FindElementById("su").Click(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); Assert.IsTrue(driver.FindElements(By.XPath("//*[contains(text(),'硒')]")).Count > 0); } catch (Exception e) { } finally { driver.Quit(); } } }
public void Back() { lock (m_lock) { navigaton.Back(); } }
public void Back() { Navigation.Back(); }
public void Back() { _navigation.Back(); }
public void Back() { navigation.Back(); upDriver.WaitForPageReady(); }
public void Back() { navigation_.Back(); frameChain_.Clear(); }
public void Back() { TryOrRetry(() => _decorated.Back()); }
public void bucleProductos(IList <IWebElement> productos, ChromeDriver driver, INavigation nav) { int cont = productos.Count; if (cont > 0) { correct = true; } if (correct) { String[] allText = new string[cont]; int i = 0; foreach (IWebElement producto in productos) { allText[i] = producto.Text; Console.WriteLine(allText[i]); i++; } // Console.WriteLine(i); IWebElement linkProducto; foreach (string nombre in allText) { try { Thread.Sleep(4000); linkProducto = driver.FindElement(By.XPath(xpathToFind: "//a[span='" + nombre + "']")); Thread.Sleep(1000); linkProducto.Click(); Console.WriteLine(nombre); try { for (int a = 0; a < 2; a++) { try { IWebElement masReseñas = driver.FindElement(By.XPath("//span[span='Cargar más reseñas internacionales']"));; masReseñas.Click(); } catch (Exception e) { } } } catch (Exception e) { Console.WriteLine("no hay más botones de reseñas" + e); } string SnumReseñas; int numReseñas = 0; string Sprecio = null; string cadenaPro; Thread.Sleep(2000); try { Sprecio = driver.FindElement(By.Id("priceblock_ourprice")).Text; SnumReseñas = driver.FindElement(By.Id("acrCustomerReviewText")).Text; numReseñas = (int)numReseñasEntero(SnumReseñas); } catch (NoSuchElementException e) { Sprecio = driver.FindElement(By.Id("priceblock_saleprice")).Text; SnumReseñas = driver.FindElement(By.Id("acrCustomerReviewText")).Text; numReseñas = (int)numReseñasEntero(SnumReseñas); } //Excepción causada al no poder insertar producto try { cadenaPro = "insert into productos (nombre, precio, numReseñas) values ('" + nombre + "','" + Sprecio + "'," + numReseñas + ")"; transac.InsertarProducto(cadenaPro); // Console.WriteLine(cadenaPro); //--------------------------------------------------------------USUARIOS Y RESEÑAS-------------------------------------------------------------- //Excepción causada por no encontrar perfil de clientes try { Thread.Sleep(3000); IList <IWebElement> perfiles = driver.FindElements(By.XPath("//span[@class='a-profile-name']")); int contaPerfiles = perfiles.Count; String[] nombres = new string[contaPerfiles]; nombres = limpiarArray(perfiles, nombres); IList <IWebElement> Ireseñas = driver.FindElements(By.XPath("//div[@class='a-expander-content reviewText review-text-content a-expander-partial-collapse-content']")); int contaReseñas = Ireseñas.Count; String[] reseñas = new string[contaReseñas]; reseñas = limpiarArray(Ireseñas, reseñas); string cadenaUsu; string rparam; for (int y = 0; y < nombres.Length; y++) { //Excepción causada por no encontrar perfil de clientes try { Console.WriteLine(nombres[y]); if (nombre[y].Equals("")) { Console.WriteLine("nombre Vacio"); } else { try { cadenaUsu = "insert into usuarios (nombre) values ('" + nombres[y] + "')"; transac.InsertarUsuario(nombres[y]); Console.WriteLine(cadenaUsu); Console.WriteLine("-----------------USUARIO INTRODUCIDO-----------------"); Thread.Sleep(500); string cadenaReseñas = "select idProducto from productos where nombre='" + nombre + "'"; int idProducto = transac.Seleccionar(cadenaReseñas); string cadenaUsuarios = "select idUsuario from usuarios where nombre='" + nombres[y] + "'"; int idUsuario = transac.Seleccionar(cadenaUsuarios); Console.WriteLine(reseñas[y]); rparam = reseñas[y]; transac.InsertarReseña(idProducto, idUsuario, rparam); Console.WriteLine("-----------------RESEÑA INTRODUCIDA-----------------"); } catch (Exception e) { Console.WriteLine(e); } Thread.Sleep(1000); } } catch (Exception e) { Console.WriteLine("----------------------------- Error: " + e); } } } catch (System.Data.SqlClient.SqlException e) { Console.WriteLine("SQL EXCEPTION--------------------------------" + e + "--------------------------------"); } } catch (NoSuchElementException) { } nav.Back(); Thread.Sleep(1000); } //Excepción causada por no encontrar enlace a producto catch (NoSuchElementException e) { Console.WriteLine("PRODUCT EXCEPTION" + e); } } correct = false; } else { correct = true; } }