Page Object Model (POM)-1
--
Page Object Model bir framework tasarım modelidir.Kodların tekrar kullanılabilirliğini,bakımını ve okunmasını kolaylaştırır.Şimdi adım adım page object model tasarımını içeren proje oluşturalım.
Adım-1:Maven Projesi oluşturma
Adım-2:pom.xml dosyasına projemizde kullanacağımız depenciesleri ekleyelim. Bizim projemizde kullanılacak dependiciesler;
Selenium-java
Webdriver Manager
TestNG
Adım-3:Page Object Model in klasör yapısını oluşturalım.Dosyalarımızı src/test/java altında oluşturuyoruz.Öncelikli olarak src/test/java altında bir paket oluşturalım, paket altında da pages, tests, utilities adında üç adet paket oluşturalım.
Adım-4:Proje seviyesinde test datalarını koyacağımız “configuration.properties
“ dosyası oluşturalım.
Adım-5:”configuration.properties” dosyasındaki verileri okumak için bir java dosyası olan “ConfigReader” classını utilities altında oluşturalım.
public class ConfigReader {
private static Properties properties;
static{
String path=”configuration.properties”;
try {
FileInputStream fileInputStream=new FileInputStream(path);
properties=new Properties();
properties.load(fileInputStream);
fileInputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getProperty(String key){
String value = properties.getProperty(key);
return value;
}
}
Adım-6:Utilities altında Driver class oluşturalım.Driver classının içeriği aşağıdaki gibidir.
public class FirstPage {
public FirstPage(){
PageFactory.initElements(Driver.getDriver(),this);
}
@FindBy(xpath =”//input[@id=’sb_form_q’]”)
public WebElement bingSearchBox;
@FindBy(css = “input#text”)
public WebElement yandexSearchBox;
@FindBy(xpath = “//input[@name=’q’]”)
public WebElement googleSearchBox;
}
Adım-8:Son olarak tests paketi altında test class ımızı oluşturalım.
public class FirstTest {
FirstPage firstPage=new FirstPage();
@Test
public void test01(){
// Driver.getDriver()==> driver
Driver.getDriver().get(ConfigReader.getProperty(“google_url”));
firstPage.googleSearchBox.sendKeys(“selenium”);
Driver.getDriver().navigate().to(ConfigReader.getProperty(“yandex_url”));
firstPage.yandexSearchBox.sendKeys(“selenium”);
Driver.getDriver().navigate().to(ConfigReader.getProperty(“bing_url”));
firstPage.bingSearchBox.sendKeys(“selenium”);
Driver.closeDriver();
}
}
Not:Tüm projenin kodlarıma https://github.com/zoomokul/POMproject adresinden ulaşabilirsiniz
Kaynaklar:
#techproeducation
#https://github.com/bulutluoz