From 888412317158ee9732e34d7fa2aebdeaea3800ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Ka=C5=88ka?= <124378142+LukasKanka@users.noreply.github.com> Date: Thu, 17 Aug 2023 13:26:38 +0200 Subject: [PATCH] POM --- Selenium_POM_tutorial/.gitignore | 38 +++++++++++++++ Selenium_POM_tutorial/.idea/.gitignore | 3 ++ Selenium_POM_tutorial/.idea/encodings.xml | 7 +++ Selenium_POM_tutorial/.idea/misc.xml | 14 ++++++ Selenium_POM_tutorial/.idea/vcs.xml | 6 +++ Selenium_POM_tutorial/pom.xml | 34 ++++++++++++++ Selenium_POM_tutorial/readme.md | 14 ++++++ .../src/main/java/POM/pages/_02/HomePage.java | 21 +++++++++ .../main/java/POM/pages/_02/LoginPage.java | 30 ++++++++++++ .../resources/META-INF/maven/archetype.xml | 9 ++++ .../resources/archetype-resources/pom.xml | 15 ++++++ .../src/main/java/App.java | 13 +++++ .../src/test/java/AppTest.java | 38 +++++++++++++++ .../tutorial/POM/tests/Test_02_Login_POM.java | 47 +++++++++++++++++++ selenide_series/.idea/misc.xml | 2 +- selenide_series/selenide_series.iml | 4 +- 16 files changed, 292 insertions(+), 3 deletions(-) create mode 100644 Selenium_POM_tutorial/.gitignore create mode 100644 Selenium_POM_tutorial/.idea/.gitignore create mode 100644 Selenium_POM_tutorial/.idea/encodings.xml create mode 100644 Selenium_POM_tutorial/.idea/misc.xml create mode 100644 Selenium_POM_tutorial/.idea/vcs.xml create mode 100644 Selenium_POM_tutorial/pom.xml create mode 100644 Selenium_POM_tutorial/readme.md create mode 100644 Selenium_POM_tutorial/src/main/java/POM/pages/_02/HomePage.java create mode 100644 Selenium_POM_tutorial/src/main/java/POM/pages/_02/LoginPage.java create mode 100644 Selenium_POM_tutorial/src/main/resources/META-INF/maven/archetype.xml create mode 100644 Selenium_POM_tutorial/src/main/resources/archetype-resources/pom.xml create mode 100644 Selenium_POM_tutorial/src/main/resources/archetype-resources/src/main/java/App.java create mode 100644 Selenium_POM_tutorial/src/main/resources/archetype-resources/src/test/java/AppTest.java create mode 100644 Selenium_POM_tutorial/src/test/java/tutorial/POM/tests/Test_02_Login_POM.java diff --git a/Selenium_POM_tutorial/.gitignore b/Selenium_POM_tutorial/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/Selenium_POM_tutorial/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Selenium_POM_tutorial/.idea/.gitignore b/Selenium_POM_tutorial/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Selenium_POM_tutorial/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Selenium_POM_tutorial/.idea/encodings.xml b/Selenium_POM_tutorial/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Selenium_POM_tutorial/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Selenium_POM_tutorial/.idea/misc.xml b/Selenium_POM_tutorial/.idea/misc.xml new file mode 100644 index 0000000..dd5e3ad --- /dev/null +++ b/Selenium_POM_tutorial/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Selenium_POM_tutorial/.idea/vcs.xml b/Selenium_POM_tutorial/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Selenium_POM_tutorial/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Selenium_POM_tutorial/pom.xml b/Selenium_POM_tutorial/pom.xml new file mode 100644 index 0000000..8a25cf8 --- /dev/null +++ b/Selenium_POM_tutorial/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + cz.lukan + Selenium_POM_tutorial_YT_Rajat + 1.0-SNAPSHOT + Archetype - Selenium_POM_tutorial_YT_Rajat + http://maven.apache.org + + 20 + 20 + + + + + org.testng + testng + 7.8.0 + test + + + + org.seleniumhq.selenium + selenium-java + 4.11.0 + + + + io.github.bonigarcia + webdrivermanager + 5.4.1 + + + diff --git a/Selenium_POM_tutorial/readme.md b/Selenium_POM_tutorial/readme.md new file mode 100644 index 0000000..9c03175 --- /dev/null +++ b/Selenium_POM_tutorial/readme.md @@ -0,0 +1,14 @@ +https://www.youtube.com/watch?v=xVlSLhB3VcA&list=PLrBBHmoBFxBWV26aLM7VHcpljfJLHd6eQ&index=1 + +Maven: + +' + 20 + 20 + ' + +TestNG + +Selenium java + +WebDriverManager \ No newline at end of file diff --git a/Selenium_POM_tutorial/src/main/java/POM/pages/_02/HomePage.java b/Selenium_POM_tutorial/src/main/java/POM/pages/_02/HomePage.java new file mode 100644 index 0000000..7206c88 --- /dev/null +++ b/Selenium_POM_tutorial/src/main/java/POM/pages/_02/HomePage.java @@ -0,0 +1,21 @@ +package POM.pages._02; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class HomePage { + WebDriver driver; + public HomePage(WebDriver driver){ + this.driver = driver; + } + // pole na vyplnění user name password,identifikace polde id + private final By msg_footer = By.xpath("//*[@id=\"page_wrapper\"]/footer/div"); + + + // ověríme text footer + public WebElement get_Msg_footer() { + return driver.findElement(msg_footer); + } + +} diff --git a/Selenium_POM_tutorial/src/main/java/POM/pages/_02/LoginPage.java b/Selenium_POM_tutorial/src/main/java/POM/pages/_02/LoginPage.java new file mode 100644 index 0000000..083ac86 --- /dev/null +++ b/Selenium_POM_tutorial/src/main/java/POM/pages/_02/LoginPage.java @@ -0,0 +1,30 @@ +package POM.pages._02; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class LoginPage { + // Webdriver potřebujeme abych mohl vyplňovat pomocí funkce fill + WebDriver driver; + + public LoginPage(WebDriver driver){ + this.driver = driver; + } + // pole na vyplnění user name password,identifikace polde id + private final By textbox_username = By.id("user-name"); + private final By textbox_password = By.name("password"); + private final By btn_login = By.xpath("//*[@id=\"login-button\"]"); + + // Vyplnění údajů + public void fill_Textbox_username(String username) { + driver.findElement(textbox_username).sendKeys(username); + } + public void fill_Textbox_password(String password) { + driver.findElement(textbox_password).sendKeys(password); + } + public void click_Btn_Login() { + driver.findElement(btn_login).click(); + } + + +} diff --git a/Selenium_POM_tutorial/src/main/resources/META-INF/maven/archetype.xml b/Selenium_POM_tutorial/src/main/resources/META-INF/maven/archetype.xml new file mode 100644 index 0000000..3a384ba --- /dev/null +++ b/Selenium_POM_tutorial/src/main/resources/META-INF/maven/archetype.xml @@ -0,0 +1,9 @@ + + Selenium_POM_tutorial_YT_Rajat + + src/main/java/App.java + + + src/test/java/AppTest.java + + diff --git a/Selenium_POM_tutorial/src/main/resources/archetype-resources/pom.xml b/Selenium_POM_tutorial/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..eeeb5a4 --- /dev/null +++ b/Selenium_POM_tutorial/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,15 @@ + + 4.0.0 + $cz.lukan + $Selenium_POM_tutorial_YT_Rajat + $1.0-SNAPSHOT + + + junit + junit + 3.8.1 + test + + + diff --git a/Selenium_POM_tutorial/src/main/resources/archetype-resources/src/main/java/App.java b/Selenium_POM_tutorial/src/main/resources/archetype-resources/src/main/java/App.java new file mode 100644 index 0000000..83671f7 --- /dev/null +++ b/Selenium_POM_tutorial/src/main/resources/archetype-resources/src/main/java/App.java @@ -0,0 +1,13 @@ +package $cz.lukan; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/Selenium_POM_tutorial/src/main/resources/archetype-resources/src/test/java/AppTest.java b/Selenium_POM_tutorial/src/main/resources/archetype-resources/src/test/java/AppTest.java new file mode 100644 index 0000000..27c1375 --- /dev/null +++ b/Selenium_POM_tutorial/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -0,0 +1,38 @@ +package $cz.lukan; + +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 ); + } +} diff --git a/Selenium_POM_tutorial/src/test/java/tutorial/POM/tests/Test_02_Login_POM.java b/Selenium_POM_tutorial/src/test/java/tutorial/POM/tests/Test_02_Login_POM.java new file mode 100644 index 0000000..a2d4f22 --- /dev/null +++ b/Selenium_POM_tutorial/src/test/java/tutorial/POM/tests/Test_02_Login_POM.java @@ -0,0 +1,47 @@ +package tutorial.POM.tests; + +import POM.pages._02.HomePage; +import POM.pages._02.LoginPage; +import io.github.bonigarcia.wdm.WebDriverManager; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class Test_02_Login_POM { + WebDriver driver; + @BeforeMethod + // open website + public void setup() { + WebDriverManager.chromedriver().setup(); + driver = new ChromeDriver(); + + driver.get("https://www.saucedemo.com/"); + driver.manage().window().maximize(); + } + + @Test + public void test_Login_Functionality() { + LoginPage loginPage = new LoginPage(driver); + loginPage.fill_Textbox_username("standard_user"); + loginPage.fill_Textbox_password("secret_sauce"); + loginPage.click_Btn_Login(); + + HomePage homePage = new HomePage(driver); + String actual_msg = homePage.get_Msg_footer().getText(); + String expected_msg = " Sauce Labs. All Rights Reserved. Terms of Service | Privacy Policy"; + + Assert.assertTrue(actual_msg.contains(expected_msg)); + + } + + // close browser + @AfterMethod + public void teardown() { + driver.quit(); + } + + +} diff --git a/selenide_series/.idea/misc.xml b/selenide_series/.idea/misc.xml index fd26528..dd5e3ad 100644 --- a/selenide_series/.idea/misc.xml +++ b/selenide_series/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/selenide_series/selenide_series.iml b/selenide_series/selenide_series.iml index becf62c..7e0b192 100644 --- a/selenide_series/selenide_series.iml +++ b/selenide_series/selenide_series.iml @@ -1,7 +1,7 @@ - - + +