Raizekas

Untitled

Apr 14th, 2021
513
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package testai;
  2.  
  3. import java.io.IOException;
  4. import java.net.MalformedURLException;
  5. import java.util.List;
  6.  
  7. import org.apache.http.HttpResponse;
  8. import org.apache.http.client.HttpClient;
  9. import org.apache.http.client.methods.HttpGet;
  10. import org.apache.http.impl.client.HttpClientBuilder;
  11. import java.net.URL;
  12. import org.junit.jupiter.api.BeforeEach;
  13. import org.junit.jupiter.api.DisplayName;
  14. import org.junit.jupiter.api.Test;
  15. import org.openqa.selenium.By;
  16. import org.openqa.selenium.JavascriptExecutor;
  17. import org.openqa.selenium.WebDriver;
  18. import org.openqa.selenium.WebElement;
  19. import org.openqa.selenium.interactions.Actions;
  20. import org.openqa.selenium.support.ui.ExpectedConditions;
  21. import org.openqa.selenium.support.ui.WebDriverWait;
  22. import selenium.SeleniumNuorodosIrAts;
  23. import selenium.SeleniumValdymas;
  24.  
  25. import java.util.List;
  26.  
  27. import static java.lang.Thread.sleep;
  28. import static org.junit.jupiter.api.Assertions.assertEquals;
  29.  
  30. public class SeleniumTest
  31. {
  32.     WebDriver driver;
  33.     WebDriverWait wait;
  34.  
  35.  
  36.     @BeforeEach
  37.     public void init()
  38.     {
  39.         driver = SeleniumValdymas.initChromeDriver();
  40.         wait = SeleniumValdymas.initWait(driver);
  41.     }
  42.  
  43.     @Test
  44.     @DisplayName("testinis testas")
  45.     public void testinisTestas()
  46.     {
  47.         WebElement searchBox;
  48.         WebElement searchButton;
  49.         WebElement prekesContaineris;
  50.         WebElement prekesIdTekstas;
  51.         driver.get(SeleniumNuorodosIrAts.getBAZINE_NUORODA());
  52.  
  53.         searchBox = driver.findElement(By.cssSelector("#searchbox .search_query"));
  54.         searchBox.click();
  55.         searchBox.sendKeys("Blouse");
  56.         searchButton = driver.findElement(By.cssSelector("#searchbox .button-search"));
  57.         searchButton.click();
  58.  
  59.         prekesContaineris = driver.findElement(By.cssSelector(".product_img_link > .replace-2x"));
  60.         prekesContaineris.click();
  61.  
  62.         prekesIdTekstas = driver.findElement(By.cssSelector("#product_reference"));
  63.  
  64.         assertEquals(SeleniumNuorodosIrAts.getPAIESKOS_TESTO_EXPECTED_MODELIS(), prekesIdTekstas.getText(), "Surastas modelis neatitinka tokio modelio, koks buvo tikėtasi testuojant");
  65.     }
  66.  
  67.     @Test
  68.     @DisplayName("antas test")
  69.     public void antarasTestinis() throws InterruptedException
  70.     {
  71.         driver.get(SeleniumNuorodosIrAts.getBAZINE_NUORODA());
  72.         Actions actions = new Actions(driver);
  73.  
  74.         sleep(5000);
  75.  
  76.         WebElement meniuMygtukas = driver.findElement(By.cssSelector(".htmlcontent-item-3 .item-img"));
  77.      //   actions.moveToElement(meniuMygtukas);
  78.      //   actions.perform();
  79.  
  80.         meniuMygtukas.click();
  81.     }
  82.  
  83.  
  84.     @Test
  85.     @DisplayName("asdasd")
  86.     public void triTest() throws InterruptedException
  87.     {
  88.         WebElement contactButton;
  89.         WebElement companyButton;
  90.         driver.get("https://www.phptravels.net/");
  91.  
  92.         driver.manage().window().maximize();
  93.         sleep(2000);
  94.  
  95.         companyButton = driver.findElement(By.cssSelector(".arrow-indicator"));
  96.         contactButton = driver.findElement(By.cssSelector(".main-nav:nth-child(2) ul a"));
  97.  
  98.         wait.until(ExpectedConditions.elementToBeClickable(companyButton));
  99.         companyButton.click();
  100.         wait.until(ExpectedConditions.elementToBeClickable(contactButton));
  101.         sleep(1000);
  102.         contactButton.click();
  103.         System.out.println(contactButton.getText());
  104.     }
  105.  
  106.     @Test
  107.     @DisplayName("ketvirtas testas")
  108.     public void ketvirtasTestasss() throws InterruptedException {
  109.         WebElement contactButton;
  110.         WebElement companyButton;
  111.         WebElement formName;
  112.         WebElement submitButton;
  113.         driver.get("https://www.phptravels.net/");
  114.  
  115.         Actions actions = new Actions(driver);
  116.  
  117.         driver.manage().window().maximize();
  118.         sleep(2000);
  119.  
  120.         companyButton = driver.findElement(By.cssSelector(".main-nav:nth-child(2) > .text-center > a"));
  121.         companyButton.click();
  122.         sleep(2000);
  123.  
  124.         contactButton = driver.findElement(By.cssSelector(".main-nav:nth-child(2) ul a"));
  125.         contactButton.click();
  126.         sleep(2000);
  127.  
  128.         formName = driver.findElement(By.cssSelector("#form_name"));
  129.         formName.sendKeys("afasdasd");
  130.  
  131.         sleep(1000);
  132.         submitButton = driver.findElement(By.name("submit_contact"));
  133.         actions.moveToElement(submitButton);
  134.         actions.click().perform();
  135.  
  136.     }
  137.  
  138.  
  139.     @Test
  140.     @DisplayName("ketvirtas testas")
  141.     public void ketvirtasTestas() throws InterruptedException
  142.     {
  143.         WebElement contactButton;
  144.         WebElement companyButton;
  145.         WebElement nameField;
  146.         WebElement emailField;
  147.         WebElement subjectField;
  148.         WebElement messageField;
  149.         WebElement submitButton;
  150.         WebElement alertMessage;
  151.  
  152.         Actions action = new Actions(driver);
  153.  
  154.         JavascriptExecutor js = (JavascriptExecutor) driver;
  155.  
  156.         driver.get("https://www.phptravels.net/");
  157.  
  158.         driver.manage().window().maximize();
  159.         Thread.sleep(2000);
  160.  
  161.         companyButton = driver.findElement(By.cssSelector(".main-nav:nth-child(2) > .text-center > a"));
  162.         companyButton.click();
  163.         Thread.sleep(2000);
  164.  
  165.         contactButton = driver.findElement(By.cssSelector(".main-nav:nth-child(2) ul a"));
  166.         contactButton.click();
  167.         Thread.sleep(2000);
  168.  
  169.         nameField = driver.findElement(By.cssSelector("#form_name"));
  170.         nameField.sendKeys("Vardenis");
  171.  
  172.         emailField = driver.findElement(By.cssSelector("#form_email"));
  173.         emailField.sendKeys("vardenis_pavardenis@gmail.com");
  174.  
  175.         subjectField = driver.findElement(By.cssSelector("#form_subject"));
  176.         subjectField.sendKeys("Klausimo tema");
  177.  
  178.         messageField = driver.findElement(By.cssSelector("#form_message"));
  179.         messageField.sendKeys("Klausimo tekstas");
  180.  
  181.     //    submitButton = driver.findElement(By.name("submit_contact"));
  182.         submitButton = driver.findElement(By.cssSelector(".btn-primary"));
  183.         action.moveToElement(submitButton);
  184.         action.perform();
  185.         Thread.sleep(2000);
  186.  
  187.         js.executeScript("window.scrollBy(0, 300)");
  188.  
  189.         submitButton.click();
  190.  
  191.         alertMessage = driver.findElement(By.cssSelector(".alert"));
  192.         assertEquals(SeleniumNuorodosIrAts.getAlertMessage(), alertMessage.getText(), "Ispejamoji zinute neatitinka");
  193.  
  194.         WebElement isvedimoLaukelis = driver.findElement(By.cssSelector("input"));
  195.         String rezultatas = isvedimoLaukelis.getAttribute("value");
  196.  
  197.         WebElement nuoroda = driver.findElement(By.cssSelector("input"));
  198.         String nuorodaTekstas = nuoroda.getAttribute("href");
  199.  
  200.     }
  201.  
  202.  
  203.     @Test
  204.     @DisplayName("Ar delete mygtukai visible")
  205.     public void testDeleteButtonsDisplayed() throws InterruptedException
  206.     {
  207.         WebElement addButton;
  208.         WebElement delete1;
  209.         WebElement delete2;
  210.         List<WebElement> deleteMygtukai;
  211.  
  212.         driver.get("http://the-internet.herokuapp.com/add_remove_elements/");
  213.  
  214.         addButton = driver.findElement(By.cssSelector(".example button"));
  215.         addButton.click();
  216.         addButton.click();
  217.         addButton.click();
  218.         addButton.click();
  219.         Thread.sleep(1000);
  220.  
  221.       /*  delete1 = driver.findElement(By.cssSelector(".added-manually:nth-child(1)"));
  222.         delete2 = driver.findElement(By.cssSelector(".added-manually:nth-child(2)"));
  223.  
  224.         System.out.println(delete1.isDisplayed());
  225.         System.out.println(delete2.isDisplayed());
  226.  
  227.         delete1.click();
  228.         delete2.click();*/
  229.  
  230.         deleteMygtukai = driver.findElements(By.cssSelector("#elements button"));
  231.  
  232.         System.out.println(deleteMygtukai.size());
  233.  
  234.         for (int i = 0; i < deleteMygtukai.size(); i++)
  235.         {
  236.             if (deleteMygtukai.get(i).isDisplayed())
  237.             {
  238.                 System.out.println(i + "-as mygtukas yra rodomas/atvaizduojamas");
  239.             }
  240.             else
  241.             {
  242.                 System.out.println(i + "-as mygtukas yra NErodomas/NEatvaizduojamas");
  243.             }
  244.         }
  245.     }
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.     @Test
  255.     @DisplayName("img test")
  256.     public void brokenImageTest()
  257.     {
  258.         List<WebElement> imgList;
  259.  
  260.         driver.get(SeleniumNuorodosIrAts.getBrokenImgUrl());
  261.  
  262.         imgList = driver.findElements(By.cssSelector("img"));
  263.  
  264.         for (int i = 0; i < imgList.size(); i++)
  265.         {
  266.             System.out.println("Asdasdsa");
  267.             try
  268.             {
  269.                 HttpClient client = HttpClientBuilder.create().build();
  270.                 HttpGet request = new HttpGet(imgList.get(i).getAttribute("src"));
  271.                 HttpResponse response = client.execute(request);
  272.  
  273.                 System.out.println(i + "   " + response.getStatusLine().getStatusCode());
  274.  
  275.             }
  276.             catch (Exception e)
  277.             {
  278.                 e.printStackTrace();
  279.             }
  280.         }
  281.     }
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. }
  289.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×