JavaApp Automated 테스트 시리즈 [v1.0.0][Page Factory 모드]
34014 단어 PageFactoryPF 모드PageFactory 모드
PageFactory 모드
PageFactory 모드의 개념은 PO와 유사하거나 확장된 것이다. 주석을 통해 요소 대상을 포지셔닝하려면 구축 함수에서 호출
PageFactory.initElements(driver,this)
하여 PO 대상을 초기화하고 페이지 대상 클래스 파일을 수정해야 한다. 코드 예시는 다음과 같다.package org.davieyang.pages;
import io.appium.java_client.android.AndroidDriver;
// PageFactory
import org.openqa.selenium.support.PageFactory;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import io.appium.java_client.MobileElement;
public class HomePage_PF {
AndroidDriver<?> driver;
public HomePage_PF(AndroidDriver<?> driver){
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
// ,
@AndroidFindBy(id="startUserRegistration")
@iOSXCUITFindBy(id="startUserRegistration")
public MobileElement startRegister_btn;
// , ,
public RegisterPage_PF navigate_register_page(){
this.startRegister_btn.click();
return new RegisterPage_PF(driver);
}
}
package org.davieyang.pages;
import java.util.List;
import org.openqa.selenium.By;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.support.PageFactory;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import io.appium.java_client.MobileElement;
public class RegisterPage_PF {
AndroidDriver<?> driver;
public RegisterPage_PF(AndroidDriver<?> driver){
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
//
//
@AndroidFindBy(id="inputUsername")
@iOSXCUITFindBy(id="inputUsername")
public MobileElement username_txt;
//
@AndroidFindBy(id="inputEmail")
@iOSXCUITFindBy(id="inputEmail")
public MobileElement email_txt;
//
@AndroidFindBy(id="inputPassword")
@iOSXCUITFindBy(id="inputPassword")
public MobileElement password_txt;
//
@AndroidFindBy(id="inputName")
@iOSXCUITFindBy(id="inputName")
public MobileElement name_txt;
//
@AndroidFindBy(id="input_preferedProgrammingLanguage")
@iOSXCUITFindBy(id="input_preferedProgrammingLanguage")
public MobileElement language_sel;
public List<MobileElement> prgLanguage;
//
@AndroidFindBy(id="input_adds")
@iOSXCUITFindBy(id="input_adds")
public MobileElement accept_check;
//
@AndroidFindBy(id="btnRegisterUser")
@iOSXCUITFindBy(id="btnRegisterUser")
public MobileElement register_btn;
public RegisterVerifyPage_PF register_sucess(String username, String email, String password, String name,
String language, String check){
this.username_txt.sendKeys(username);
this.email_txt.sendKeys(email);
this.password_txt.sendKeys(password);
this.name_txt.clear();
this.name_txt.sendKeys(name);
this.language_sel.click();
checkedTextView(language);
if(check.equals("Yes")){
if(!this.accept_check.isSelected())
this.accept_check.click();
}
this.register_btn.click();
return new RegisterVerifyPage_PF(driver);
}
public void checkedTextView(String language){
// class , list
@SuppressWarnings("unchecked")
List<MobileElement> checkTextViews = (List<MobileElement>) driver
.findElementsByClassName("android.widget.CheckedTextVeiw");
// for List , name Ruby
// click
for (MobileElement checkedTextView:checkTextViews){
if(checkedTextView.getAttribute("name").equals(language)){
if(!checkedTextView.isSelected()){
checkedTextView.click();
}
}
}
}
}
package org.davieyang.pages;
import org.openqa.selenium.By;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.support.PageFactory;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.MobileElement;
public class RegisterVerifyPage_PF {
AndroidDriver<?> driver;
public RegisterVerifyPage_PF(AndroidDriver<?> driver){
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
//
@AndroidFindBy(id="label_name_data")
@iOSXCUITFindBy(id="label_name_data")
public MobileElement label_name_data;
//
@AndroidFindBy(id="label_username_data")
@iOSXCUITFindBy(id="label_username_data")
public MobileElement label_username_data;
//
@AndroidFindBy(id="label_password_data")
@iOSXCUITFindBy(id="label_password_data")
public MobileElement label_password_data;
//
@AndroidFindBy(id="label_email_data")
@iOSXCUITFindBy(id="label_email_data")
public MobileElement label_email_data;
//
@AndroidFindBy(id="label_preferedProgrammingLanguage_data")
@iOSXCUITFindBy(id="label_preferedProgrammingLanguage_data")
public MobileElement label_preferedProgrammingLanguage_data;
//
@AndroidFindBy(id="label_acceptAdds_data")
@iOSXCUITFindBy(id="label_acceptAdds_data")
public MobileElement label_acceptAdds_data;
// ,
public String get_name_value(){
return this.label_name_data.getTagName().toString();
}
// ,
public String get_username_value(){
return this.label_username_data.getTagName().toString();
}
// ,
public String get_password_value(){
return this.label_password_data.getTagName().toString();
}
// ,
public String get_email_value(){
return this.label_email_data.getTagName().toString();
}
// ,
public String get_preferedProgrammingLanguage_value(){
return this.label_preferedProgrammingLanguage_data.getTagName().toString();
}
// ,
public String get_acceptAdds_value(){
return this.label_acceptAdds_data.getTagName().toString();
}
}