This commit is contained in:
Lukáš Kaňka 2023-08-16 18:56:52 +02:00
parent 233f276f6f
commit 295204768e
15 changed files with 4659 additions and 3 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -5,8 +5,9 @@ TestNG ---> https://mvnrepository.com/artifact/org.testng/testng (pom.xml)
Maven ---> Maven --->
''''
<properties> <properties>
<maven.compiler.source>20</maven.compiler.source> <maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target> <maven.compiler.target>20</maven.compiler.target>
</properties> </properties>
'''

View File

@ -0,0 +1,31 @@
package specs;
import com.codeborne.selenide.Condition;
import org.testng.annotations.Test;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;
// zde otestujeme dotazník pro zákazníka který vyplníme.
public class FormTest {
@Test
public void testFormFields() {
open("https://practice.sdetunicorns.com/support-form/");
// vyplň všechny pole
$(".support-name input").val("Fanda");
$(".support-email input").val("Fanda@vidle.com");
$(".support-subject input").val("Nechce to splachovat");
// dropdown a checkbox
$(".support-dropdown select").selectOption("Technical Team");
$(".support-checkboxes ul li:nth-child(2) input").click();
// vyber datum
$(".support-date input").click();
$(".flatpickr-day.nextMonthDay").click();
// klikni na Submit tlačítkko
$("button[type=submit]").click();
// ověř submit zprávu
$("div[role=alert]").shouldHave(Condition.text("Thanks for contacting us! We will be in touch with you shortly."));
}
}

View File

@ -1,11 +1,17 @@
package specs; package specs;
import com.codeborne.selenide.CollectionCondition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.WebDriverRunner; import com.codeborne.selenide.WebDriverRunner;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test; import org.testng.annotations.Test;
// pro každou novou funkci pomocí AlT + Enter můžeme přidat hvězdičku a ušetříme řádky
import java.util.List;
import static com.codeborne.selenide.Selenide.open; import static com.codeborne.selenide.Condition.*;
import static com.codeborne.selenide.Selenide.title; import static com.codeborne.selenide.Selenide.*;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertEquals;
public class HomeTest { public class HomeTest {
@ -24,6 +30,46 @@ public class HomeTest {
@Test @Test
public void testInteractingWithElements() { public void testInteractingWithElements() {
open("https://practice.sdetunicorns.com/");
// klikneme na tlačítko podle id
$(By.id("get-started")).click();
// zkontrolujeme očekávanou URL máme dva způsoby
String url = WebDriverRunner.url();
//assertEquals(url, "https://practice.sdetunicorns.com/#get-started");
assertTrue(url.contains("get-started"));
// najdeme objeckt podle cssSelector a zkontrolujeme jeho text ( zde je to třída h1 class )
$("h1")
.should(text("Think different. Make different."));
// Ověříme logo pomocí xpath
$(By.xpath("//*[@id=\"zak-masthead\"]/div/div/div/div[1]/div/a/img"))
.should(be(visible));
}
@Test
public void testMultipleElements() {
open("https://practice.sdetunicorns.com/");
// zkontrolujeme názvy v menu (horní lišta)
// $$ znamená že pracujeme s více elementy
// vytvoříme si pak proměnou linklists
//za li[id. . .] je id na položky v menu
List<String> expectedLinks = List.of("Home", "About", "Shop", "Blog", "Contact", "My account");
ElementsCollection linkLists = $$("#zak-primary-menu li[id*=menu-item]");
// vypíšeme do console položky menu
System.out.println(linkLists.texts());
//porovnáme výsledek z našimy zadanými hodnoty na začátku testu
List<String> linkListsText = linkLists.texts();
assertEquals(linkListsText, expectedLinks);
// a kratší způsob zápisu
linkLists.shouldHave(CollectionCondition.texts(expectedLinks));
} }
} }