Last active
August 29, 2015 14:27
-
-
Save rafaelcs/e1fe99a84d52e62aa989 to your computer and use it in GitHub Desktop.
Help user Selenium_groups - Structure test
This file contains hidden or 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.Collections.Generic; | |
using System.Text; | |
using NUnit.Framework; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Chrome; | |
using OpenQA.Selenium.Support.UI; | |
using OpenQA.Selenium.Remote; | |
using OpenQA.Selenium.Interactions; | |
using System.Collections.ObjectModel; | |
namespace Carros_CSX_ | |
{ | |
public class CSX_FechaReservaUsuarioB2B | |
{ | |
public IWebDriver driver; | |
public String baseURL; | |
public String dataRetiradaTelaResultado, dataDevolucaoTelaResultado, dataRetiradaTelaPagamento, dataDevolucaoTelaPagamento, valorPrecoCarrinho, valorTotalCarrinho; | |
public int numeroDeDiarias; | |
public IWebElement diariaPrimeiroVeiculo; | |
public String valorDiariaTelaResultado, valorDiariaTelaPagamento, valorTotalAluguel, mensagemErro; | |
public String nomeVeiculoTelaResultado, nomeVeiculoTelaPagamento; | |
public String localRetiradaTelaResultado, localRetiradaTelaPagamento; | |
public String taxasGerais, taxaRetorno, totalTaxas; | |
public float taxasGeraisConvertida = 0, taxaRetornoConvertida = 0, totalTaxasConvertida = 0, diferencaTotalAluguel_TotalCarrinho, valorTotalCarrinhoConvertido; | |
public float valorTotalDiarias, valorDiariaTelaPagamentoConvertido = 0, valorTotalAluguelConvertido = 0, valorDiariaTelaResultadoConvertido = 0, calculoValorTotalAluguel, valorPrecoCarrinhoConvertido = 0; | |
public int masterCard; | |
[TestFixtureSetUp] | |
public void Setup() | |
{ | |
baseURL = "http://testing.com"; | |
driver = new ChromeDriver(@"C:\Users\rafael.carvalho\Documents\Visual Studio 2010\Projects"); | |
driver.Manage().Window.Maximize(); | |
} | |
[Test] | |
public void a_EfetuarLoginB2B() | |
{ | |
driver.Navigate().GoToUrl(baseURL); | |
driver.FindElement(By.Id("txtLogin")).SendKeys("[email protected]"); | |
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl00_Login_1_txtPassword")).SendKeys("123456"); | |
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl00_Login_1_btnLogin")).Click(); | |
WebDriverWait esperaAcessarLogin = new WebDriverWait(driver, TimeSpan.FromSeconds(3)); | |
esperaAcessarLogin.Until(ExpectedConditions.ElementIsVisible(By.Id("p_lt_ctl01_LoggedMenu_1_lblWelcomeMessage"))); | |
Assert.AreEqual("Bem vindo(a), Empresa B2B", driver.FindElement(By.Id("p_lt_ctl01_LoggedMenu_1_lblWelcomeMessage")).Text); | |
} | |
[Test] | |
public void b_PreencherBuscaSomenteRetirada() | |
{ | |
driver.FindElement(By.ClassName("Carros")).Click(); | |
WebDriverWait esperaAparecerBuscador = new WebDriverWait(driver, TimeSpan.FromSeconds(15)); | |
esperaAparecerBuscador.Until(ExpectedConditions.ElementIsVisible(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl00_CSXBuscador_txtPickupLocation_txtDestinations_txtDescription"))); | |
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl00_CSXBuscador_txtPickupLocation_txtDestinations_txtDescription")).SendKeys("congonhas"); | |
WebDriverWait esperaAparecerNomeCidade = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); | |
esperaAparecerNomeCidade.Until(ExpectedConditions.ElementIsVisible(By.ClassName("ac_results"))); | |
driver.FindElement(By.CssSelector("strong")).Click(); | |
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl00_CSXBuscador_bdpPickupDate")).Click(); | |
for (int i = 0; i < 4; i++) | |
{ | |
driver.FindElement(By.CssSelector(".ui-icon.ui-icon-circle-triangle-e")).Click(); | |
} | |
driver.FindElement(By.XPath("//a[contains(text(),'1')]")).Click(); | |
System.Threading.Thread.Sleep(1000); | |
driver.FindElement(By.Id("btnSearchCSX")).Click(); | |
WebDriverWait esperaTelaResultado = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); | |
esperaTelaResultado.Until(ExpectedConditions.ElementIsVisible(By.Id("lblPickupLocation"))); | |
} | |
[Test] | |
public void c_SelecionaVeiculo() | |
{ | |
// Armazena os dados do resultado da busca - Cidade e Período | |
localRetiradaTelaResultado = driver.FindElement(By.Id("lblPickupLocation")).Text; | |
dataRetiradaTelaResultado = driver.FindElement(By.Id("lblDateCheckin")).Text; | |
dataDevolucaoTelaResultado = driver.FindElement(By.Id("lblDateCheckout")).Text; | |
// Calcula o numero de diárias que o carro será alugado | |
TimeSpan data = Convert.ToDateTime(dataDevolucaoTelaResultado) - | |
Convert.ToDateTime(dataRetiradaTelaResultado); | |
numeroDeDiarias = data.Days; | |
// Armazena os dados do primeiro veículo que aparece na lista de resultado | |
ReadOnlyCollection<IWebElement> diariaPrimeiroVeiculo = driver.FindElements(By.Id("best-value")); | |
valorDiariaTelaResultado = diariaPrimeiroVeiculo[0].Text; | |
ReadOnlyCollection<IWebElement> nomePrimeiroVeiculo = driver.FindElements(By.Id("car-name")); | |
nomeVeiculoTelaResultado = nomePrimeiroVeiculo[0].Text; | |
ReadOnlyCollection<IWebElement> botaoReservar = driver.FindElements(By.ClassName("btn-add-cart")); | |
botaoReservar[0].Click(); | |
System.Threading.Thread.Sleep(2000); | |
//WebDriverWait esperaTelaPagamento = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); | |
//esperaTelaPagamento.Until(ExpectedConditions.ElementIsVisible(By.Id("local-period"))); | |
} | |
[Test] | |
public void d_VerificaValoresListaDoCarrinho() | |
{ | |
driver.FindElement(By.ClassName("shopping-cart-intems-number")).Click(); | |
valorPrecoCarrinho = driver.FindElement(By.ClassName("icon-cart-price")).Text; | |
String valorPrecoCarrinhoSub = valorPrecoCarrinho.Substring(3, 6); | |
float.TryParse(valorDiariaTelaResultado, out valorDiariaTelaResultadoConvertido); // Converte valor da diária da tela de pagamento para INTEIRO | |
float.TryParse(valorPrecoCarrinhoSub, out valorPrecoCarrinhoConvertido); | |
calculoValorTotalAluguel = valorDiariaTelaResultadoConvertido * numeroDeDiarias; // Este calculo retorna o valor EXATO do total das diárias | |
if (calculoValorTotalAluguel != valorPrecoCarrinhoConvertido) | |
{ | |
diferencaTotalAluguel_TotalCarrinho = calculoValorTotalAluguel - valorPrecoCarrinhoConvertido; | |
if (diferencaTotalAluguel_TotalCarrinho > 0.10f) | |
{ | |
System.Console.WriteLine("diferencaTotalAluguel_TotalCarrinho É MAIOR QUE 10 CENTAVOS"); | |
} | |
} | |
else | |
{ | |
Assert.AreEqual(calculoValorTotalAluguel, valorPrecoCarrinhoConvertido); | |
} | |
valorTotalCarrinho = driver.FindElement(By.ClassName("icon-cart-price-total")).Text; | |
String valorTotalCarrinhoSub = valorTotalCarrinho.Substring(3, 6); | |
float.TryParse(valorTotalCarrinhoSub, out valorTotalCarrinhoConvertido); | |
Assert.AreEqual(valorPrecoCarrinhoConvertido, valorTotalCarrinhoConvertido); | |
driver.FindElement(By.Id("btCart")).Click(); | |
WebDriverWait esperaTelaPagamento1 = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); | |
esperaTelaPagamento1.Until(ExpectedConditions.ElementIsVisible(By.ClassName("header-1"))); | |
} | |
[Test] | |
public void e_ValidaTelaCarrinhoDeCompras() | |
{ | |
Assert.IsTrue(driver.FindElement(By.Id("btBuy")).Displayed); | |
//IWebElement mensagemErro = driver.FindElement(By.Id("btBuy")); | |
//if (mensagemErro.) | |
//{ | |
// System.Console.WriteLine("Olá"); | |
//} | |
//else | |
//{ | |
// System.Console.WriteLine("Não Olá"); | |
//} | |
} | |
//[Test] | |
//public void e_PreencheDadosTelaPagamentoComCartão() | |
//{ | |
// // Preenche dados do condutor | |
// driver.FindElement(By.Id("txtName")).SendKeys("rafael"); | |
// driver.FindElement(By.Id("txtSurName")).SendKeys("carvalho"); | |
// new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtBirth"))).Click().SendKeys("10021991").Build().Perform(); | |
// // | |
//} | |
//[Test] | |
//public void f_TearDown() | |
//{ | |
// driver.Quit(); | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment