我在登录测试方法中面临奇怪的执行行为。我在selenium Grid下运行这段代码。并将Grid配置为独立服务器。因此,我首先使用批处理文件启动硒网格(Hub \ Node),以便通过测试执行。java中代码执行的奇怪行为
以下是我的课程和规格。 代码: 1. pojDataSource.java:
public class pojDataSource {
private static WebElement element = null;
private static List<WebElement> elements = null;
public static WebElement txt_UserName(WebDriver driver){
driver.findElement(By.id("txtUserName")).clear();
element = driver.findElement(By.id("txtUserName"));
return element;
}
public static WebElement txt_Password(WebDriver driver){
driver.findElement(By.id("txtPassword")).clear();
element = driver.findElement(By.id("txtPassword"));
return element;
}
}
clsConstant.java:
public class clsConstant { public static final String URL = "http://localhost:1234/"; public static final String Username = "username"; public static final String Password = "password"; }
ModuleTest.java:
public class ModuleTest { public RemoteWebDriver mDriver = null; public DesiredCapabilities mCapability = new DesiredCapabilities() ; public WebElement mWebElement = null; public String mBaseURL = clsConstant.URL; public static clsExcelSampleData mAddConnectorXls; @Test public void beforeMethod() throws Exception { WebDriverWait wdw =null; mCapability.setCapability("platform", org.openqa.selenium.Platform.WINDOWS); mCapability = DesiredCapabilities.firefox(); mCapability.setVersion("45.0.2"); mDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"), mCapability); mDriver.get(mBaseURL); mDriver.manage().window().maximize(); pojDataSource.txt_UserName(mDriver).sendKeys(clsConstant.Username) ; pojDataSource.txt_Password(mDriver).sendKeys(clsConstant.Password) ; pojDataSource.btn_LogIn(mDriver).click(); }
当我在eclipe的DEBUG模式下执行代码在IDE中,它向我展示了奇怪的行为。首先它启动浏览器并通过登录屏幕打开mBaseURL成功。加载页面后,它会在浏览器中显示默认的用户名\密码。
现在当调试点来到pojDataSource.txt_UserName(mDriver).sendKeys(clsConstant.Username);线。通过按F5,我的调试点转到pojDataSource.txt_Password();行并且它读取错误的密码并且脚本执行失败。我担心如果我的调试点在用户名,但仍然会获取密码的值,会如何发生?
试过的解决方案: 1.由于我使用Firefox浏览器来运行测试。我从浏览器中清除我的密码。
感谢Lucrib。但是在我新的Eclipse版本中重新导入这个项目之前,我能够完美地运行相同的代码。 – Ishekh
不错。因此,在这个问题上添加这些信息。 – lucrib