配置:
OS : Ubuntu
Java version : 8
Selenium : 3.8.0
ChromeDriver : 2.33
Chrome version : 60
我正在自动化一个应用程序,我必须使用社交媒体登录系统
输入手机号码后,会要求输入密码和社交媒体图标。如果我点击让我们说google plus,它会打开谷歌加登录窗口,然后我必须提供凭证,然后窗口自动关闭,用户登录。如图所示
我的问题是,从我的应用程序退出后,如果我再次尝试使用google plus登录,那么它会执行自动登录(第二次它不会要求谷歌加凭据,因为谷歌加会话cookie都在那里)
所以在我的脚本中,我试图在第一次测试后删除所有的cookie,但它不是我尝试过的代码行:
driver.manage().deleteAllCookies();
参考完整测试如下:
@Test
public void newUserRegistration_GooglePlus_ForAlreadyExistEmail() throws IOException, InterruptedException, JSONException
{
LogoutAnalyzer.checkLogout();
loginpage.sendUsername(excel.getCellData(6, 18, 1));
CommonMethods.waitUntilLoaderGetInvisible(driver);
TakeScreenshot.passedScreenShot("Username");
LogWriter.logger.info("Mobile number has entered");
loginpage.clickSubmitButton();
CommonMethods.waitUntilLoaderGetInvisible(driver);
LogWriter.logger.info("Submit button clicked");
if(loginpage.otpTextbox.size()>0)
{
String OTP = otpreader.getOTP(excel.getCellData(6, 18, 1));
LogWriter.logger.info("Got the OTP via API call OTP is "+OTP);
loginpage.enterOTP(OTP);
TakeScreenshot.passedScreenShot("OTP_Entered");
LogWriter.logger.info("OTP Entered");
loginpage.clickConfirmCodeButton();
CommonMethods.waitUntilLoaderGetInvisible(driver);
LogWriter.logger.info("Submit button clicked");
TakeScreenshot.passedScreenShot("Profile_Info");
loginpage.clickGooglePlusIcon();
Thread.sleep(5000);
LogWriter.logger.info("Switch to Google Plus window");
CommonMethods.switchWindow(driver);
CommonMethods.waitForElementVisibility(driver, new RCONGooglePlusPage(driver).usernameField);
TakeScreenshot.passedScreenShot("Google Window");
sm_helper.googlePlusLogin(excel.getCellData(6, 18, 2), excel.getCellData(6, 18, 3));
CommonMethods.switchToParentWindow(driver);
LogWriter.logger.info("Switched back to RContacts window");
CommonMethods.waitUntilLoaderGetInvisible(driver);
Assert.assertEquals(loginpage.getValidationMessage(), PropertyFileReader.getProperty("emailAlreadyExistMessage"));
LogWriter.logger.info(PropertyFileReader.getProperty("emailAlreadyExistMessage"));
}
else
{
TakeScreenshot.passedScreenShot("Already_registered_User");
LogWriter.logger.info("This user is already a registered user");
}
driver.manage().deleteAllCookies();
LogWriter.logger.info("all cookies deleted");
}