SHARE
TWEET

Untitled

a guest Jul 18th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import org.junit.Assert;
  9. import org.junit.Test;
  10. import org.openqa.selenium.By;
  11. import org.openqa.selenium.WebElement;
  12. import org.openqa.selenium.chrome.ChromeDriver;
  13. import org.openqa.selenium.support.ui.Select;
  14.  
  15. public class CampoTreinamento {
  16.     public CampoTreinamento() {
  17.     }
  18.  
  19.     @Test
  20.     public void interagirComTextField() {
  21.         ChromeDriver driver = new ChromeDriver();
  22.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  23.         driver.findElement(By.id("elementosForm:nome")).sendKeys(new CharSequence[]{"teste"});
  24.         Assert.assertEquals("teste", driver.findElement(By.id("elementosForm:nome")).getAttribute("value"));
  25.         driver.close();
  26.     }
  27.  
  28.     @Test
  29.     public void interagirRadioButton() {
  30.         ChromeDriver driver = new ChromeDriver();
  31.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  32.         driver.findElement(By.id("elementosForm:sexo:0")).click();
  33.         Assert.assertTrue(driver.findElement(By.id("elementosForm:sexo:0")).isSelected());
  34.         driver.close();
  35.     }
  36.  
  37.     @Test
  38.     public void interagirCheckBox() {
  39.         ChromeDriver driver = new ChromeDriver();
  40.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  41.         driver.findElement(By.id("elementosForm:comidaFavorita:0")).click();
  42.         Assert.assertTrue(driver.findElement(By.id("elementosForm:comidaFavorita:0")).isSelected());
  43.         driver.close();
  44.     }
  45.  
  46.     @Test
  47.     public void interagirDropdown() {
  48.         ChromeDriver driver = new ChromeDriver();
  49.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  50.         Select dropdown = new Select(driver.findElement(By.id("elementosForm:escolaridade")));
  51.         dropdown.selectByVisibleText("Doutorado");
  52.         Assert.assertEquals("Doutorado", dropdown.getFirstSelectedOption().getText());
  53.         dropdown.selectByValue("mestrado");
  54.         Assert.assertEquals("Mestrado", dropdown.getFirstSelectedOption().getText());
  55.         driver.close();
  56.     }
  57.  
  58.     @Test
  59.     public void interagirMultipleSelection() {
  60.         ArrayList<String> saidaEsperada = new ArrayList();
  61.         saidaEsperada.add("Corrida");
  62.         saidaEsperada.add("O que eh esporte?");
  63.         ArrayList<String> saidaReal = new ArrayList();
  64.         ChromeDriver driver = new ChromeDriver();
  65.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  66.         Select lista = new Select(driver.findElement(By.id("elementosForm:esportes")));
  67.         lista.selectByVisibleText("Corrida");
  68.         lista.selectByIndex(4);
  69.         List<WebElement> selecionados = lista.getAllSelectedOptions();
  70.  
  71.         int i;
  72.         for(i = 0; i < selecionados.size(); ++i) {
  73.             saidaReal.add(((WebElement)selecionados.get(i)).getText());
  74.         }
  75.  
  76.         for(i = 0; i < selecionados.size(); ++i) {
  77.             Assert.assertEquals(saidaEsperada.get(i), saidaReal.get(i));
  78.         }
  79.  
  80.         driver.close();
  81.     }
  82.  
  83.     @Test
  84.     public void interagirTextField() {
  85.         ChromeDriver driver = new ChromeDriver();
  86.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  87.         driver.findElement(By.id("elementosForm:sugestoes")).sendKeys(new CharSequence[]{"teste"});
  88.         Assert.assertEquals("teste", driver.findElement(By.id("elementosForm:sugestoes")).getAttribute("value"));
  89.         driver.close();
  90.     }
  91.  
  92.     @Test
  93.     public void interagirBotaoTabela() {
  94.         ChromeDriver driver = new ChromeDriver();
  95.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  96.         WebElement botaoDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[3]/input"));
  97.         botaoDentroDaCelula.click();
  98.         String mensagem = driver.switchTo().alert().getText();
  99.         driver.switchTo().alert().accept();
  100.         Assert.assertEquals("Francisco", mensagem);
  101.     }
  102.  
  103.     @Test
  104.     public void interagirTabela() {
  105.         ChromeDriver driver = new ChromeDriver();
  106.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  107.         WebElement botaoDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[3]/input"));
  108.         botaoDentroDaCelula.click();
  109.         String mensagem = driver.switchTo().alert().getText();
  110.         driver.switchTo().alert().accept();
  111.         Assert.assertEquals("Francisco", mensagem);
  112.         WebElement CheckBoxDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[4]/input[@type='checkbox']"));
  113.         CheckBoxDentroDaCelula.click();
  114.         Assert.assertTrue(CheckBoxDentroDaCelula.isSelected());
  115.         WebElement RadioDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[5]//tr[1]/td[1]/input[@type='radio']"));
  116.         RadioDentroDaCelula.click();
  117.         Assert.assertTrue(RadioDentroDaCelula.isSelected());
  118.         WebElement TextFieldDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[6]/input[@type='text']"));
  119.         TextFieldDentroDaCelula.sendKeys(new CharSequence[]{"linha1"});
  120.         Assert.assertEquals("linha1", TextFieldDentroDaCelula.getAttribute("value"));
  121.         driver.close();
  122.     }
  123.  
  124.     @Test
  125.     public void interagirPaginaCompleta() {
  126.         ChromeDriver driver = new ChromeDriver();
  127.         driver.get("file:///" + System.getProperty("user.dir") + "/src/main/resources/componentes.html");
  128.         driver.findElement(By.id("elementosForm:nome")).sendKeys(new CharSequence[]{"campoNome"});
  129.         driver.findElement(By.id("elementosForm:sobrenome")).sendKeys(new CharSequence[]{"campoSobrenome"});
  130.         driver.findElement(By.id("elementosForm:sexo:1")).click();
  131.         driver.findElement(By.id("elementosForm:comidaFavorita:2")).click();
  132.         Select dropdown = new Select(driver.findElement(By.id("elementosForm:escolaridade")));
  133.         dropdown.selectByVisibleText("Superior");
  134.         Select lista = new Select(driver.findElement(By.id("elementosForm:esportes")));
  135.         lista.selectByVisibleText("Natacao");
  136.         lista.selectByVisibleText("Karate");
  137.         driver.findElement(By.id("elementosForm:sugestoes")).sendKeys(new CharSequence[]{"Sugestão"});
  138.         WebElement botaoDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[3]/input"));
  139.         botaoDentroDaCelula.click();
  140.         driver.switchTo().alert().accept();
  141.         WebElement CheckBoxDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[4]/input[@type='checkbox']"));
  142.         CheckBoxDentroDaCelula.click();
  143.         WebElement RadioDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[5]//tr[1]/td[1]/input[@type='radio']"));
  144.         RadioDentroDaCelula.click();
  145.         Assert.assertTrue(RadioDentroDaCelula.isSelected());
  146.         WebElement TextFieldDentroDaCelula = driver.findElement(By.xpath("//table[@id='elementosForm:tableUsuarios']/tbody/tr[1]/td[6]/input[@type='text']"));
  147.         TextFieldDentroDaCelula.sendKeys(new CharSequence[]{"linha1"});
  148.         driver.findElement(By.id("elementosForm:cadastrar")).click();
  149.         WebElement resultado = driver.findElement(By.id("resultado"));
  150.         String Esperado = "Cadastrado!\nNome: campoNome\nSobrenome: campoSobrenome\nSexo: Feminino\nComida: Pizza\nEscolaridade: superior\nEsportes: Natacao Karate\nSugestoes: Sugestão";
  151.         Assert.assertEquals(Esperado, resultado.getText());
  152.         driver.close();
  153.     }
  154. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top