/ ****试图在不同的类中但在同一浏览器实例中执行多个测试用例。但是我面临的问题是,第二个测试套件总是尝试打开新窗口或会话。但是我只想打开相同的浏览器,而不是总是打开新窗口。请帮助。**** /
公共类LoginPage扩展了BaseClass {
@FindBy(xpath="//a[contains(text(),'Login & Signup')]")
private WebElement LoginLink;
@FindBy(xpath="(//form/div/input[@type='text'])")
private WebElement UnTxBx;
@FindBy(xpath="//input[@type='password']")
private WebElement PwdTxBx;
@FindBy(xpath="(//button[@type='submit'])[last()]")
private WebElement loginBtn;
@FindBy(xpath="//span[contains(text(),'Your username or password is incorrect')]")
private WebElement invalidLoginMsg;
//Intializing Page Object
public LoginPage()
{
PageFactory.initElements(driver, this);
}
public FKartHome login(String username, String password)
{
//// LoginLink.click();
// WaitStatementLib.eWaitForVisible(10, UnTxBx);
UnTxBx.sendKeys(username);
PwdTxBx.sendKeys(password);
loginBtn.click();
return new FKartHome();
}
//This is my Login Page
public class FKartHome extends BaseClass {
@FindBy(xpath="//input[@title='Search for products, brands and more']")
private WebElement SearchSendKeys;
@FindBy(xpath="//button[@type='submit']")
private WebElement ClickSubmit;
public FKartHome()
{
PageFactory.initElements(driver, this);
}
public ItemsPage search(String searchBook)
{
WaitStatementLib.eWaitForVisible(20, SearchSendKeys);
SearchSendKeys.sendKeys(searchBook);
ClickSubmit.click();
return new ItemsPage();
}
//这是我的主页
public class LoginPageTest extends BaseClass {
public static LoginPage loginPage;
public static FKartHome fKartHome;
@Test
public static void loginTest()
{
String filepath= "/home/ambrish/Lockdown_Tets/SeleniumPractice/TestDataSheet/testdata.xlsx";
String username = ExcelUtilities.readData(filepath, "sheet1", 1, 1);
//System.out.println(username);
String password = ExcelUtilities.readData(filepath, "sheet1", 1, 2);
//System.out.println(password);
LoginPage lp = new LoginPage();
//fKartHome=loginPage.login(username, password);
lp.login(username, password);
}
//这是我的第一个TestCase类
@FindBy(xpath="//input[@title='Search for products, brands and more']")
private WebElement SearchSendKeys;
@FindBy(xpath="//button[@type='submit']")
private WebElement ClickSubmit;
public FKartHome()
{
PageFactory.initElements(driver, this);
}
public ItemsPage search(String searchBook)
{
WaitStatementLib.eWaitForVisible(20, SearchSendKeys);
SearchSendKeys.sendKeys(searchBook);
ClickSubmit.click();
return new ItemsPage();
}
}
//This is my 2nd TestClass