Pessoal, atualmente eu estou com um problema no IF e ELSE. O código está abaixo:
public class SolicitaReservaVooSite
{
public IWebDriver driver;
public String baseURL;
public int IncrementMonth = 3;
[TestFixtureSetUp]
public void Setup()
{
baseURL = "http://teste.com/";
driver = new ChromeDriver(@"D:\automatedtests\tools\drivers");
driver.Manage().Window.Maximize();
}
[Test]
public void a_AcessarSistema()
{
driver.Navigate().GoToUrl(baseURL);
}
[Test]
public void b_EfetuarPesquisaVoosSomenteIda()
{
driver.FindElement(By.Id("rbtOnlyWay")).Click();
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_FSXBuscador_txtDeparture_txtDescription")).SendKeys("bage");
WebDriverWait esperaAutoPreenchimentoOrigem = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
esperaAutoPreenchimentoOrigem.Until(ExpectedConditions.ElementIsVisible(By.ClassName("ac_results")));
driver.FindElement(By.ClassName("ac_even")).Click();
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_FSXBuscador_txtArrival_txtDescription")).SendKeys("miami");
WebDriverWait esperaAutoPreenchimentoDestino = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
esperaAutoPreenchimentoDestino.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@class='ac_even ac_over']")));
driver.FindElement(By.XPath("//*[@class='ac_even ac_over']")).Click();
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_FSXBuscador_txtDepartureDateAero")).Click();
for (int i = 0; i < IncrementMonth; i++)
{
driver.FindElement(By.CssSelector("span.ui-icon.ui-icon-circle-triangle-e")).Click();
}
driver.FindElement(By.XPath("//td[1]/a")).Click();
System.Threading.Thread.Sleep(1000);
driver.FindElement(By.Id("btnSearchFSX")).Click();
System.Threading.Thread.Sleep(5000);
/*WebDriverWait esperaAparecerMatriz = new WebDriverWait(driver, TimeSpan.FromMinutes(2));
esperaAparecerMatriz.Until(ExpectedConditions.ElementIsVisible(By.Id("principalMatrix")));*/
}
[Test]
public void c_RetornaResultados()
{
try
{
driver.FindElement(By.CssSelector(".grpFlight0")).Click();
Assert.AreEqual("Porto Alegre", driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl02_FSXResultados_groupedResults_lblTextoFlashDeparture")).Text);
Assert.AreEqual("Miami", driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl02_FSXResultados_groupedResults_lblTextoFlashArrival")).Text);
Assert.AreEqual("1", driver.FindElement(By.Id("numAdults")).Text);
driver.FindElement(By.ClassName("resultado-voos-item-reservar")).Click();
WebDriverWait esperaResultado = new WebDriverWait(driver, TimeSpan.FromMinutes(2));
esperaResultado.Until(ExpectedConditions.ElementIsVisible(By.ClassName("billing-address-form")));
}
catch (NoSuchElementException)
{
driver.Navigate().GoToUrl(baseURL);
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_FSXBuscador_txtDeparture_txtDescription")).Clear();
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_FSXBuscador_txtArrival_txtDescription")).Clear();
IncrementMonth++;
}
[b] if (IncrementMonth <= 5)
{
b_EfetuarPesquisaVoosSomenteIda();
c_RetornaResultados();
}
else
{
Console.WriteLine("Não foi encontrado nenhum resultado!");
}[/b]
}
[Test]
public void d_PreencheDadosPagamentoCartãoCrédito()
{
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_txtName_ADT_0")).SendKeys("dsdas");
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_txtSurname_ADT_0")).SendKeys("dsds");
SelectElement dataNascimento = new SelectElement(driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_ddlSex_ADT_0")));
dataNascimento.SelectByValue("M");
new Actions(driver).MoveToElement(driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_txtBorn_ADT_0"))).Click().SendKeys("10021991").Build().Perform();
//Preenche dados do cartão
SelectElement parcelamento = new SelectElement(driver.FindElement(By.Name("p$lt$ctl03$pageplaceholder$p$lt$ctl01$pageplaceholder$p$lt$ctl01$FSXPagamento$optionsPagto")));
parcelamento.SelectByValue("1");
driver.FindElement(By.Id("txtCreditCardName")).SendKeys("rafael asdsadas");
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtCpfNumber"))).Click().SendKeys("01967164037").Build().Perform();
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtCreditCardNumber"))).Click().SendKeys("5555666677778844").Build().Perform();
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtCreditCardMonth"))).Click().SendKeys("10").Build().Perform();
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtCreditCardYear"))).Click().SendKeys("18").Build().Perform();
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtCreditCardSecurityNumber"))).Click().SendKeys("999").Build().Perform();
//Preenche dados da fatura do cartão
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtCep"))).Click().SendKeys("92120020").Build().Perform();
driver.FindElement(By.Id("txtNumber")).SendKeys("800");
//Preenche informações do bilhete eletronico
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_txtBilheteEletronicoNome")).SendKeys("asdsadsadsdas");
driver.FindElement(By.Id("txtBilheteEletronicoEmail")).SendKeys("asdasdasdas");
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtPhoneDDD"))).Click().SendKeys("51").Build().Perform();
new Actions(driver).MoveToElement(driver.FindElement(By.Id("txtPhone"))).Click().SendKeys("95854515").Build().Perform();
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_chkContract1")).Click();
driver.FindElement(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXPagamento_ibnConfirm")).Click();
}
[Test]
public void e_ValidaTelaReservaConfirmada()
{
WebDriverWait esperaFinalizarReserva = new WebDriverWait(driver, TimeSpan.FromMinutes(2));
esperaFinalizarReserva.Until(ExpectedConditions.ElementIsVisible(By.Id("p_lt_ctl03_pageplaceholder_p_lt_ctl01_pageplaceholder_p_lt_ctl01_FSXConfirmacao_divPnrCode")));
try
{
Console.WriteLine("passou");
}
catch (NoSuchElementException)
{
Console.WriteLine("não passou");
}
}
[TestFixtureTearDown]
public void TearDown()
{
driver.Quit();
}
}
}
Sempre quando executar o IF e ele for igual à 5, mesmo assim ele está executando o próximo método. Eu preciso apenas que quando execute Console.WriteLine(“Não foi encontrado nenhum resultado!”); já finalize o teste, pois não tem porque rodar o próximo método.