daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.chrome.ChromeDriver;
  7. import org.openqa.selenium.support.ui.ExpectedConditions;
  8. import org.openqa.selenium.support.ui.WebDriverWait;
  9.  
  10. public class Main {
  11.     public static void main(String[] args) {
  12.         System.setProperty("webdriver.chrome.driver", "C:\\Users\\bernam\\Downloads\\chromedriver.exe");
  13.         WebDriver browser = new ChromeDriver();
  14.         browser.get("http://algirdaskuslys.000webhostapp.com/selenium/pazintys.php");
  15.  
  16.         String vardoTekstas = "Gebenė Kukūškina";
  17.         String lytiesTekstas = "Moteris";
  18.         String koIeškoTekstas = "Vyro";
  19.  
  20.         waitForElementByName(browser, 1, "vardas");
  21.  
  22.         WebElement vardoLaukas = browser.findElement(By.name("vardas"));
  23.         WebElement lytiesLaukas = browser.findElement(By.name("lytis"));
  24.         WebElement koIeškoLaukas = browser.findElement(By.name("iesko"));
  25.  
  26.         vardoLaukas.sendKeys(vardoTekstas);
  27.         lytiesLaukas.sendKeys(lytiesTekstas);
  28.         koIeškoLaukas.sendKeys(koIeškoTekstas);
  29.  
  30.         waitForElementByXpath(browser,1,"//*[@id=\"form\"]/form/button");
  31.         WebElement siuntimoMygtukas = browser.findElement(By.xpath("//*[@id=\"form\"]/form/button"));
  32.         siuntimoMygtukas.click();
  33.  
  34.         WebElement visasBody = browser.findElement(By.tagName("body"));
  35.         waitForTextPresent(browser, 1, visasBody, "New record created successfuly");
  36.  
  37.         String visasBodyTekstas = visasBody.getText();
  38.  
  39. //        String išvalytasTekstas = visasBodyTekstas.replace("Pažinčių registracijos forma\n\n\n\nSiųsti\n", "");
  40.  
  41. //        if(išvalytasTekstas.equals("New record created successfuly")){
  42. //            System.out.println("Tests pavyko!");
  43. //        } else {
  44. //            System.out.println("Tests NEpavyko!");
  45. //        }
  46.  
  47.         if(visasBodyTekstas.contains("New record created successfuly")){
  48.             System.out.println("Tests pavyko!");
  49.         } else {
  50.             System.out.println("Tests NEpavyko!");
  51.         }
  52.  
  53.         browser.close();
  54.     }
  55.  
  56.     static private void waitForElementByName (WebDriver browser, int timeOutInSec, String Name){
  57.         WebDriverWait waitas = new WebDriverWait(browser, timeOutInSec);
  58.         waitas.until(ExpectedConditions.elementToBeClickable(By.name(Name)));
  59.     }
  60.  
  61.     static private void waitForElementByXpath (WebDriver browser, int timeOutInSec, String Xpath){
  62.         WebDriverWait waitas = new WebDriverWait(browser,timeOutInSec);
  63.         waitas.until(ExpectedConditions.elementToBeClickable(By.xpath(Xpath)));
  64.     }
  65.  
  66.     static private void waitForTextPresent (WebDriver browser, int timeOutInSec, WebElement element, String text){
  67.         WebDriverWait waitas = new WebDriverWait(browser, timeOutInSec);
  68.         waitas.until(ExpectedConditions.textToBePresentInElement(element, text));
  69.     }
  70. }
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
 
Top