pages objects
This commit is contained in:
parent
7957d1cffa
commit
f5db7f2a13
8
selenide_series/.idea/modules.xml
generated
Normal file
8
selenide_series/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/selenide_series.iml" filepath="$PROJECT_DIR$/selenide_series.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -11,3 +11,9 @@ Maven --->
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
</properties>
|
||||
'''
|
||||
|
||||
PageObjects -->
|
||||
|
||||
vytvořit složku pages v test/Java, --> Mark Directory -->Test Sources Root (pouze zě nemám java kde vznikají package)
|
||||
|
||||
Pak si v testu na importovat pages object např: import pages.HomePage;
|
10
selenide_series/selenide_series.iml
Normal file
10
selenide_series/selenide_series.iml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/page" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/spec" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/specs" isTestSource="true" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
40
selenide_series/src/test/java/pages/HomePage.java
Normal file
40
selenide_series/src/test/java/pages/HomePage.java
Normal file
@ -0,0 +1,40 @@
|
||||
package pages;
|
||||
|
||||
import com.codeborne.selenide.ElementsCollection;
|
||||
import com.codeborne.selenide.Selenide;
|
||||
import com.codeborne.selenide.SelenideElement;
|
||||
import com.codeborne.selenide.WebDriverRunner;
|
||||
import org.openqa.selenium.By;
|
||||
|
||||
import static com.codeborne.selenide.Selenide.*;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
public class HomePage {
|
||||
public HomePage open() {
|
||||
Selenide.open("https://practice.sdetunicorns.com/");
|
||||
return this;
|
||||
}
|
||||
// pomocí ALT+Enter si vytvoříme v červeném (jako importy) řádku com.codeborne.selenide.SelenideElement
|
||||
// pak s toho vytvoříme import com.codeborne.selenide.SelenideElement;
|
||||
//pak mužeme odmazat níže část s com.codeborne.selenide.
|
||||
public SelenideElement getStaredBtn() {
|
||||
return $(By.id("get-started"));
|
||||
}
|
||||
public SelenideElement headingTitle() {
|
||||
return $("h1");
|
||||
}
|
||||
public SelenideElement logoLink() {
|
||||
return $(By.xpath("//*[@id=\"zak-masthead\"]/div/div/div/div[1]/div/a/img"));
|
||||
}
|
||||
//zde vracíme kolekci elementu tak proto ElementsCollection
|
||||
public ElementsCollection linksList() {
|
||||
return $$("#zak-primary-menu li[id*=menu-item]");
|
||||
}
|
||||
|
||||
public void assertUrl(String expectedURL) {
|
||||
String url = WebDriverRunner.url();
|
||||
assertEquals(url, expectedURL);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package specs;
|
||||
|
||||
|
||||
import com.codeborne.selenide.CollectionCondition;
|
||||
import com.codeborne.selenide.ElementsCollection;
|
||||
import com.codeborne.selenide.WebDriverRunner;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.testng.annotations.Test;
|
||||
import pages.HomePage;
|
||||
// pro každou novou funkci pomocí AlT + Enter můžeme přidat hvězdičku a ušetříme řádky
|
||||
import java.util.List;
|
||||
|
||||
@ -15,13 +17,18 @@ import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
public class HomeTest {
|
||||
HomePage home = new HomePage();
|
||||
@Test
|
||||
public void testPageUrlAndTitle() {
|
||||
open("https://practice.sdetunicorns.com/");
|
||||
// home page z page objects
|
||||
home
|
||||
.open() // můžeme i řetězit
|
||||
.assertUrl("https://practice.sdetunicorns.com/");
|
||||
|
||||
|
||||
// test očekávané url, String url do této proměné jsme vložily url
|
||||
String url = WebDriverRunner.url();
|
||||
assertEquals(url, "https://practice.sdetunicorns.com/");
|
||||
// *page*
|
||||
// home.assertUrl("https://practice.sdetunicorns.com/");
|
||||
|
||||
// test titulu stránky
|
||||
String title = title();
|
||||
@ -32,8 +39,8 @@ public class HomeTest {
|
||||
public void testInteractingWithElements() {
|
||||
open("https://practice.sdetunicorns.com/");
|
||||
|
||||
// klikneme na tlačítko podle id
|
||||
$(By.id("get-started")).click();
|
||||
// klikneme na tlačítko podle id * page_object *
|
||||
home.getStaredBtn().click();
|
||||
|
||||
// zkontrolujeme očekávanou URL máme dva způsoby
|
||||
String url = WebDriverRunner.url();
|
||||
@ -41,11 +48,12 @@ public class HomeTest {
|
||||
assertTrue(url.contains("get-started"));
|
||||
|
||||
// najdeme objeckt podle cssSelector a zkontrolujeme jeho text ( zde je to třída h1 class )
|
||||
$("h1")
|
||||
// *pages object
|
||||
home.headingTitle()
|
||||
.should(text("Think different. Make different."));
|
||||
|
||||
// Ověříme logo pomocí xpath
|
||||
$(By.xpath("//*[@id=\"zak-masthead\"]/div/div/div/div[1]/div/a/img"))
|
||||
// Ověříme logo pomocí xpath * pages*
|
||||
home.logoLink()
|
||||
.should(be(visible));
|
||||
}
|
||||
|
||||
@ -58,7 +66,7 @@ public class HomeTest {
|
||||
// vytvoříme si pak proměnou linklists
|
||||
//za li[id. . .] už 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]");
|
||||
ElementsCollection linkLists = home.linksList();
|
||||
|
||||
// vypíšeme do console položky menu
|
||||
System.out.println(linkLists.texts());
|
||||
|
BIN
selenide_series/target/test-classes/pages/HomePage.class
Normal file
BIN
selenide_series/target/test-classes/pages/HomePage.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user