This commit is contained in:
Lukáš Kaňka 2023-08-17 13:26:38 +02:00
parent 6fa38ba917
commit 8884123171
16 changed files with 292 additions and 3 deletions

38
Selenium_POM_tutorial/.gitignore vendored Normal file
View File

@ -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

3
Selenium_POM_tutorial/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

14
Selenium_POM_tutorial/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
Selenium_POM_tutorial/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,34 @@
<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>cz.lukan</groupId>
<artifactId>Selenium_POM_tutorial_YT_Rajat</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Archetype - Selenium_POM_tutorial_YT_Rajat</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.4.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
https://www.youtube.com/watch?v=xVlSLhB3VcA&list=PLrBBHmoBFxBWV26aLM7VHcpljfJLHd6eQ&index=1
Maven:
'<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
</properties>'
TestNG
Selenium java
WebDriverManager

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,9 @@
<archetype>
<id>Selenium_POM_tutorial_YT_Rajat</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>$cz.lukan</groupId>
<artifactId>$Selenium_POM_tutorial_YT_Rajat</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 $cz.lukan;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -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 );
}
}

View File

@ -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();
}
}

View File

@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="20" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module version="4"> <module version="4">
<component name="NewModuleRootManager"> <component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/test/page" isTestSource="true" /> <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/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/specs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/specs" isTestSource="true" />