-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompletarFormulario.cs
92 lines (76 loc) · 3.87 KB
/
CompletarFormulario.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System.Collections.Generic;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
namespace EjercicioPractico
{
public class CompletarFormulario
{
private IWebDriver driver;
[SetUp]
public void Setup()
{
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
}
[TearDown]
public void TearDown()
{
driver.Quit();
}
[Test]
[Description("Se completan todos los del formulario.")]
public void IngresoCompletoCampos()
{
driver.Navigate().GoToUrl("https://demo.seleniumeasy.com/input-form-demo.html");
Assert.That(driver.Title, Is.EqualTo("Selenium Easy - Input Form Demo with Validations"));
driver.FindElement(By.Name("first_name")).SendKeys("Leonardo");
driver.FindElement(By.Name("last_name")).SendKeys("Perez");
driver.FindElement(By.Name("email")).SendKeys("lperez@ces.com.uy");
driver.FindElement(By.Name("phone")).SendKeys("(845)555-1212");
driver.FindElement(By.Name("address")).SendKeys("Direccion");
driver.FindElement(By.Name("city")).SendKeys("Ciudad");
new SelectElement(driver.FindElement(By.Name("state"))).SelectByText("Virginia");
driver.FindElement(By.Name("zip")).SendKeys("98370");
driver.FindElement(By.Name("website")).SendKeys("ces.com.uy");
driver.FindElements(By.Name("hosting"))[0].Click();
driver.FindElement(By.Name("comment")).SendKeys("Esto es un comentario.");
driver.FindElement(By.CssSelector(".btn")).Click();
IList<IWebElement> listaEtiquetasSmall = driver.FindElements(By.TagName("small"));
bool invalid = false;
foreach (var item in listaEtiquetasSmall)
if (item.GetAttribute("data-bv-result").Equals("INVALID"))
invalid = true;
Assert.IsFalse(invalid, "Se encuentra una verificacion pendiente.");
}
[Test]
[Description("Se completan todos los del formulario menos nombre.")]
public void NoIngresamosNombre()
{
driver.Navigate().GoToUrl("https://demo.seleniumeasy.com/input-form-demo.html");
Assert.That(driver.Title, Is.EqualTo("Selenium Easy - Input Form Demo with Validations"));
driver.FindElement(By.Name("last_name")).SendKeys("Perez");
driver.FindElement(By.Name("email")).SendKeys("lperez@ces.com.uy");
driver.FindElement(By.Name("phone")).SendKeys("(845)555-1212");
driver.FindElement(By.Name("address")).SendKeys("Direccion");
driver.FindElement(By.Name("city")).SendKeys("Ciudad");
new SelectElement(driver.FindElement(By.Name("state"))).SelectByText("Virginia");
driver.FindElement(By.Name("zip")).SendKeys("98370");
driver.FindElement(By.Name("website")).SendKeys("ces.com.uy");
driver.FindElements(By.Name("hosting"))[0].Click();
driver.FindElement(By.Name("comment")).SendKeys("Esto es un comentario.");
driver.FindElement(By.CssSelector(".btn")).Click();
//Otra forma en la que podemos validar
IList<IWebElement> listaEtiquetasSmall = driver.FindElements(By.TagName("small"));
List<string> listaDataBvResult = new List<string>();
foreach (var item in listaEtiquetasSmall)
listaDataBvResult.Add(item.GetAttribute("data-bv-result"));
Assert.IsFalse(listaDataBvResult.Contains("INVALID"), "Se encuentra una verificacion pendiente.");
}
}
}