Created
February 11, 2012 23:26
-
-
Save diegocaxito/1805006 to your computer and use it in GitHub Desktop.
Criando Testes de Interface em .Net com Selenium WebDriver para a aplicação NerdDinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Threading; | |
using NUnit.Framework; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Firefox; | |
using OpenQA.Selenium.Support.UI; | |
using OpenQA.Selenium.IE; | |
namespace SeleniumTests | |
{ | |
[TestFixture] | |
public class CadastrarDinnerTeste | |
{ | |
private IWebDriver driver; | |
private StringBuilder verificationErrors; | |
private string baseURL; | |
[SetUp] | |
public void SetupTest() | |
{ | |
driver = new FirefoxDriver(); | |
baseURL = "http://localhost/NerdDinner/"; | |
verificationErrors = new StringBuilder(); | |
} | |
[TearDown] | |
public void TeardownTest() | |
{ | |
try | |
{ | |
driver.Quit(); | |
} | |
catch (Exception) | |
{ | |
// Ignore errors if unable to close the browser | |
} | |
Assert.AreEqual("", verificationErrors.ToString()); | |
} | |
[Test] | |
public void CadastrarDinner_QuandoPassarDadosDoJantar_DeveCadastrarEExibirEmLista() | |
{ | |
var titulo = string.Format("Teste {0}", DateTime.Now.ToString("yyyy-MM-dd hh:mm")); | |
driver.Navigate().GoToUrl(baseURL); | |
driver.FindElement(By.CssSelector("a.logo")).Click(); | |
driver.FindElement(By.LinkText("Host Dinner")).Click(); | |
driver.FindElement(By.Id("username")).Clear(); | |
driver.FindElement(By.Id("username")).SendKeys("teste"); | |
driver.FindElement(By.Id("password")).Clear(); | |
driver.FindElement(By.Id("password")).SendKeys("teste123"); | |
driver.FindElement(By.CssSelector("input.classiclogon")).Click(); | |
driver.FindElement(By.Id("Dinner_Title")).Clear(); | |
driver.FindElement(By.Id("Dinner_Title")).SendKeys(titulo); | |
driver.FindElement(By.Id("Dinner_Description")).Clear(); | |
driver.FindElement(By.Id("Dinner_Description")).SendKeys(titulo); | |
driver.FindElement(By.Id("Dinner_Address")).Clear(); | |
driver.FindElement(By.Id("Dinner_Address")).SendKeys("São Paulo, SP"); | |
new SelectElement(driver.FindElement(By.Id("Dinner_Country"))).SelectByText("Brazil"); | |
driver.FindElement(By.Id("Dinner_ContactPhone")).Clear(); | |
driver.FindElement(By.Id("Dinner_ContactPhone")).SendKeys("teste"); | |
driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click(); | |
var textoCadastrado = driver.FindElement(By.ClassName("summary")).Text; | |
StringAssert.AreEqualIgnoringCase(titulo, textoCadastrado); | |
driver.FindElement(By.LinkText("Log Off")).Click(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Threading; | |
using NUnit.Framework; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Firefox; | |
using OpenQA.Selenium.Support.UI; | |
using OpenQA.Selenium.IE; | |
namespace SeleniumTests | |
{ | |
public abstract class CadastrarDinnerTesteBase | |
{ | |
protected IWebDriver driver; | |
protected string baseURL; | |
private StringBuilder verificationErrors; | |
[Test] | |
public void Cadastrar_QuandoPassarDadosDoJantar_DeveCadastrar_e_ExibirEmLista() | |
{ | |
var titulo = string.Format("Teste {0}", DateTime.Now.ToString("yyyy-MM-dd hh:mm")); | |
driver.Navigate().GoToUrl(baseURL); | |
driver.FindElement(By.CssSelector("a.logo")).Click(); | |
driver.FindElement(By.LinkText("Host Dinner")).Click(); | |
driver.FindElement(By.Id("username")).Clear(); | |
driver.FindElement(By.Id("username")).SendKeys("teste"); | |
driver.FindElement(By.Id("password")).Clear(); | |
driver.FindElement(By.Id("password")).SendKeys("teste123"); | |
driver.FindElement(By.CssSelector("input.classiclogon")).Click(); | |
driver.FindElement(By.Id("Dinner_Title")).Clear(); | |
driver.FindElement(By.Id("Dinner_Title")).SendKeys(titulo); | |
driver.FindElement(By.Id("Dinner_Description")).Clear(); | |
driver.FindElement(By.Id("Dinner_Description")).SendKeys(titulo); | |
driver.FindElement(By.Id("Dinner_Address")).Clear(); | |
driver.FindElement(By.Id("Dinner_Address")).SendKeys("São Paulo, SP"); | |
new SelectElement(driver.FindElement(By.Id("Dinner_Country"))).SelectByText("Brazil"); | |
driver.FindElement(By.Id("Dinner_ContactPhone")).Clear(); | |
driver.FindElement(By.Id("Dinner_ContactPhone")).SendKeys("teste"); | |
driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click(); | |
var textoCadastrado = driver.FindElement(By.CssSelector("h2.summary")).Text; | |
StringAssert.AreEqualIgnoringCase(titulo, textoCadastrado); | |
driver.FindElement(By.LinkText("Log Off")).Click(); | |
} | |
[TearDown] | |
public void TeardownTest() | |
{ | |
try | |
{ | |
driver.Quit(); | |
} | |
catch (Exception) | |
{ | |
// Ignore errors if unable to close the browser | |
} | |
Assert.AreEqual("", verificationErrors.ToString()); | |
} | |
[SetUp] | |
public void SetupTest() | |
{ | |
driver = ObterDriver(); | |
baseURL = "http://localhost/NerdDinner/"; | |
verificationErrors = new StringBuilder(); | |
} | |
public abstract IWebDriver ObterDriver(); | |
} | |
[TestFixture] | |
public class CadastrarDinnerInternetExplorerTeste : CadastrarDinnerTesteBase | |
{ | |
public override IWebDriver ObterDriver() | |
{ | |
return new InternetExplorerDriver(); | |
} | |
} | |
[TestFixture] | |
public class CadastrarDinnerFirefoxTeste : CadastrarDinnerTesteBase | |
{ | |
public override IWebDriver ObterDriver() | |
{ | |
return new FirefoxDriver(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interessante Diego, eu estava procurando uma solução simples sem ter que configurar o Selenium Grid e sua ideia caiu como uma luva.