moohamed
This commit is contained in:
2
Selenium_POM_tutorial/.idea/misc.xml
generated
2
Selenium_POM_tutorial/.idea/misc.xml
generated
@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -11,4 +11,4 @@ TestNG
|
||||
|
||||
Selenium java
|
||||
|
||||
WebDriverManager
|
||||
konec video 3
|
@ -0,0 +1,21 @@
|
||||
package POM.pages._03;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package POM.pages._03;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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_03_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();
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user