我已经为日志一页写了一个简单的基于 Sel的自动化文字。 但是,我有一个单独的页面物体和方法类别,另一个可变部件类别,然后是测试类别。
Page objects and methods
public class LoginPage extends ReusableComponents {
WebDriver driver;
@FindBy(xpath="//input[@name= username ]")
public WebElement in_username;
@FindBy(xpath="//input[@name= password ]")
WebElement in_password;
@FindBy(xpath="//button[@type= submit ]")
WebElement btn_submit;
public LoginPage(WebDriver driver) {
super(driver);
this.driver = driver;
PageFactory.initElements(driver, this);
}
public void enterUname(String uname) {
in_username.sendKeys(uname);
}
public void enterPassword(String pass) {
in_password.sendKeys(pass);
}
public void clickSubmit() {
btn_submit.click();
}
}
Reusable component class
public class ReusableComponents {
WebDriver driver;
public ReusableComponents(WebDriver driver) {
this.driver = driver;
}
public void setup() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
}
public void waitElementToAppear(WebElement findby){
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated((By) findby));
}
public void closeBrowser() {
driver.close();
}
}
Test class
public class OpenBrowser {
static WebDriver driver;
public static void main(String[] args) {
LoginPage login = new LoginPage(driver);
ReusableComponents common = new ReusableComponents(driver);
common.setup();
common.waitElementToAppear(login.in_username);
login.enterUname("Admin");
login.enterPassword("admin123");
login.clickSubmit();
common.closeBrowser();
}
}
Error Log
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 31559
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jun 29, 2023 8:43:53 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.ClassCastException: class jdk.proxy2.$Proxy4 cannot be cast to class org.openqa.selenium.By (jdk.proxy2.$Proxy4 is in module jdk.proxy2 of loader app ; org.openqa.selenium.By is in the unnamed module of loader app )
at com.orange.reusablecomponents.ReusableComponents.waitElementToAppear(ReusableComponents.java:32)
at com.orangehrm.OpenBrowser.main(OpenBrowser.java:27)
如果我对“用户名称”标的置换式的测试,那么它给我留下的错误就象我在此附上的那样。 请有人帮助我解决这个问题?
错误的筛选:
我试图制造一个网点,但却没有帮助。