public void tearDown()
{
driver.quit();
}
public void signInFacebook(String link) throws InterruptedException {
log.header("USER SIGN IN VIA FACEBOOK");
log.step("Click the Sign In Link");
clickLink(link);
Thread.sleep(3000);
log.log("click success.......");
log.step("Click 'Sign in with Facebook' Link ");
// Store the current window handle
String parentHandle = driver.getWindowHandle();
// Perform the click operation that opens new window
driver.findElement(By.cssSelector(CONSTANTs.FB_SIGN_IN)).click();
Thread.sleep(5000);
// Switch to new window opened
log.divider("Facebook Login Screen.....Enter Details Below");
for (String childHandle : driver.getWindowHandles()) {
driver.switchTo().window(childHandle);
if (!childHandle.equals(parentHandle)) {
log.step("Enter Email address");
driver.findElement(By.cssSelector(CONSTANTs.FB_EMAIL_TXTBOX))
.sendKeys(CONSTANTs.EMAIL_ADDRESS);
Thread.sleep(2000);
log.step("Enter password");
driver.findElement(By.cssSelector(CONSTANTs.FB_PASSWORD_TXTBOX))
.sendKeys(CONSTANTs.FB_PASSWORD);
Thread.sleep(2000);
log.step("Click Log_In button");
driver.findElement(By.cssSelector(CONSTANTs.LOG_IN)).click();
Thread.sleep(2000);
log.log("Check for First Sign In or Return User.......wait");
WebDriver switchPage = driver.switchTo().window(parentHandle);
try {
if (switchPage.getWindowHandle().contains(parentHandle)) {
driver.switchTo().window(childHandle);
log.log("Indo App NOT installed..... Click Ok to accept FB permissions...");
optionalClick(By.cssSelector(CONSTANTs.OK_CONTINUE_AS));
driver.switchTo().window(parentHandle);
}
log.log("DONE....... ");
// break;
} catch (Exception e) {
log.log("Indo App Already exist on Users Fb acct ... Move to next screen");
}
break;
}
}
log.log("Check if User is Signed In or Has Signed In with another account.......wait");
Thread.sleep(5000);
try {
if ((driver.findElement(By.cssSelector(CONSTANTs.MY_ACCOUNT_LINK)))
.isDisplayed()) {
log.log("First Sign In ....... Successfully Logged in Using FB.");
Thread.sleep(3000);
tearDown();
}
} catch (Exception e) {
log.header2("Second Sign In ...... User Already signed In with a different Acct........ pls wait");
}
driver.switchTo().window(parentHandle);
Thread.sleep(3000);
try {
if (driver.findElement(
By.cssSelector(CONSTANTs.ALREADY_SIGNED_UP_PASSWD_TXTBOX))
.isDisplayed()) {
log.log("User Already signed Up with a NATIVE acct .....Please Enter Password for Native acct");
driver.findElement(
By.cssSelector(CONSTANTs.ALREADY_SIGNED_UP_PASSWD_TXTBOX))
.sendKeys(CONSTANTs.NATIVE_PASSWORD);
Thread.sleep(2000);
driver.findElement(
By.cssSelector(CONSTANTs.ALREADY_SIGNED_UP_BTN))
.click();
Thread.sleep(2000);
log.log("Successfully Linked NATIVE acct with FB.");
Thread.sleep(3000);
tearDown();
}
} catch (Exception e1) {
log.log(" acct....wait, checking other acct......");
}
try{
if (driver.findElement(
By.cssSelector(CONSTANTs.SIGN_IN_WITH_GOOGLE_BTN))
.isDisplayed()) {
log.log("User is Signed in Already with GOOGLE account ... Click Google button to Link account.");
Thread.sleep(3000);
driver.findElement(
By.cssSelector(CONSTANTs.SIGN_IN_WITH_GOOGLE_BTN))
.click();
Thread.sleep(2000);
log.log("Successfully Linked .");
Thread.sleep(3000);
tearDown();
}
}
catch(Exception e2) {
log.log("No Google acct present either.... Please contact Gigya customer support....");
Thread.sleep(3000);
tearDown();
}
}
我试图在我的代码的任何阶段通过测试后关闭浏览器,但我不断收到错误,在坚果壳中尝试做的是,如果我的测试在任何阶段通过,请不要继续代码执行,不要挂起,关闭浏览器。如果我有tearDown(),请仔细看看。如果此时登录成功,则浏览器应在sleep()之后关闭。
拜托,我已经检查了以前的解决方案,但没有为我工作。 Driver.close或quit应该可以工作,但不是,也许我做错了..... 感谢您提前提供任何帮助。
线程中的异常" main" org.openqa.selenium.remote.SessionNotFoundException:会话ID为空。调用quit()后使用WebDriver? 构建信息:版本:' 2.45.0',修订版:' 32a636c',时间:' 2015-03-05 22:01:35' 系统信息:主持人:' Ola-PC',ip:' 10.255.253.14',os.name:' Windows 7',os.arch:&# 39; amd64',os.version:' 6.1',java.version:' 1.7.0_76' 驱动程序信息:driver.version:RemoteWebDriver 在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:125) 在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:66) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572) 在org.openqa.selenium.remote.RemoteWebDriver $ RemoteTargetLocator.window(RemoteWebDriver.java:890) 在com.independent.helper.testPageNavi.signInFacebook(testPageNavi.java:475) 在com.independent.helper.testing.main(testing.java:113)
答案 0 :(得分:2)
您正在关闭一个特定测试后的webdriver。这是一个很好的评估,但您需要为每个要运行的新测试启动一个新的webdriver。
您有两种选择。 1.每次测试后制作一个新的webdriver。 2.导航回到开始页面,以便开始新的测试。
我建议选项1。
-initWithData:error: