This commit is contained in:
Lukáš Kaňka
2023-08-11 14:32:41 +02:00
commit a8f58c8ec4
19 changed files with 457 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<archetype>
<id>SeleniumBasic</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>

View File

@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>$kankys</groupId>
<artifactId>$SeleniumBasic</artifactId>
<version>$1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package $kankys;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -0,0 +1,38 @@
package $kankys;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

View File

@ -0,0 +1,39 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ClickMeTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL + "/clickmebaby.php");
// message jsem udělal do getText vložit "" vyjmout --> vlažit kam chci psát
Assert.assertEquals("Inicaálizovaný počet kliků", "0", driver.findElement(By.id("clicks")).getText());
// for cyklus zvyšování plus 1
for (int i = 1; i <11 ; i++) {
driver.findElement(By.id("clickMe")).click();
Assert.assertEquals(String.valueOf(i),driver.findElement(By.id("clicks")).getText());
if (i==1){
System.out.println("ověřujem slovo klik");
Assert.assertEquals("klik",driver.findElement(By.className("desription")).getText());
}
// dálší info video 28
}
}
@After
public void tearDown(){
driver.quit();
}
}

View File

@ -0,0 +1,36 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class CssSelectorTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL + "/kalkulacka.php");
// id
driver.findElement(By.cssSelector("button#count")).click();
// class - trida
driver.findElement(By.cssSelector("button.btn-success")).click();
driver.get(BASE_URL + "/clickmebaby.php");
// tlačítko je v poli container a v něm je button
driver.findElement(By.cssSelector("div.container button")).click();
}
@After
public void tearDown(){
// driver.quit();
}
}

View File

@ -0,0 +1,30 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
// @neco je metota těmi začneme psát test
// void = metoda nevrací žádnou hodnotu
// setUP, test, tearDown názvy metod mohu si je pojmenovat jak chci
public class MySecondTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL + "/clickmebaby.php");
driver.findElement(By.id("clickMe")).click();
}
@After
public void tearDown(){
driver.quit();
}
}

View File

@ -0,0 +1,32 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
// @neco je metota těmi začneme psát test
// void = metoda nevrací žádnou hodnotu
// setUP, test, tearDown názvy metod mohu si je pojmenovat jak chci
public class MyThirdTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL + "/registracia.php");
driver.findElement(By.name("email")).sendKeys("franta@borec.cz");
driver.findElement(By.name("name")).sendKeys("Franta");
driver.findElement(By.xpath("//form/div[3]/input")).sendKeys("frantík");
}
@After
public void tearDown(){
driver.quit();
}
}

View File

@ -0,0 +1,50 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.fail;
public class SelectTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() {
//System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test(){
driver.get(BASE_URL + "/vybersi.php");
new Select(driver.findElement(By.className("form-control"))).selectByIndex(1);
new Select(driver.findElement(By.className("form-control"))).selectByValue("02");
new Select(driver.findElement(By.className("form-control"))).selectByVisibleText("Pikachu");
// výpis textu
System.out.println(driver.findElement(By.xpath("//div/h3")).getText());
// kontrola jestli se v textu nalézá Pikachu
Assert.assertTrue("Pikachu se v textu nenachází", driver.findElement(By.xpath("//div/h3")).getText().contains("Pikachu"));
// kontrola jestli se nenalézé něco jiného v textu ( v tomto prípadě Gizela)
Assert.assertFalse(driver.findElement(By.xpath("//div/h3")).getText().contains("Gizela"));
}
@After
public void tearDown(){
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}

View File

@ -0,0 +1,28 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TabulkaTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL + "/tabulka.php");
// video 31
driver.findElement(By.xpath("//table/tbody/tr[last()]/td[1]")).getText();
}
@After
public void tearDown(){
driver.quit();
}
}

View File

@ -0,0 +1,26 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class VzorTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL);
}
@After
public void tearDown(){
driver.quit();
}
}

View File

@ -0,0 +1,27 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class XpathTest {
private WebDriver driver;
private final String BASE_URL = "http://localhost";
@Before
public void setUp(){
driver = new ChromeDriver();
}
@Test
public void test(){
driver.get(BASE_URL + "/tabulka.php");
driver.findElement(By.xpath("/html/body/div/div/table/thead/tr"));
}
@After
public void tearDown(){
// driver.quit();
}
}