Google login flow automation on iOS app


#1

Recently Google has changed the oauth for the app login using google plus account.
Now we have option to have it handled in Safari or Google app.

On Safari I could login, press Allow permissions buttons.

But after this an alert window is displayed which says, Open the app or continue to google account.

I am unable to act on this alert as it is displayed for mere 2 seconds.
driver.switchTo().alert().accept(); does not act on this and it navigates to Safari Gmail page.

Unless I handle this alert I will not be logged in to my app.

Could anyone help me out for pressing the “Open” button on this alert.

Appreciate the help !!


#2

Try this, if your query is for Safari Browser on Iphone. I am having troubles with the google login on ios app? Have you found any solution for that?

public void performLoginWithGoogle(String gmailId, String gmailPswd)
{
String hkWinHndl = iosDriver.getWindowHandle();
System.out.println(“Current Title ::” + iosDriver.getTitle());
AccLoginPage.clickGoogleLoginBtn();
comnFunc.staticWait(5);
try
{
homeSteps.verifySuccessfullLoginGmail();
System.out.println(“Already logged in”);
}
catch(Exception eParent)
{
for (String allHandles : iosDriver.getWindowHandles()) {
iosDriver.switchTo().window(allHandles);
System.out.println(“current window title :” + iosDriver.getTitle());
if(iosDriver.getTitle().contains(“in”)) {
System.out.println(“Switched to Google window…”);
GlobalVar.test.log(LogStatus.INFO, “Switched to Google window…”);
System.out.println(iosDriver.getContext());

				Set<String> handles = iosDriver.getContextHandles();
				for(String e :  handles)
				{
					System.out.println(e);
					if(e.contains("WEBVIEW"))
					{
						iosDriver.context(e);
						try
						{
							iosDriver.findElement(By.id("identifierId"));
						}
						catch(Exception e2)
						{
							System.out.println("Trying other context");
						}
					}
				}
				try
				{
				WebElement gmailUserInpt = iosDriver.findElement(By.id("identifierId"));
				comnFunc.sendKeysThroughJavaScript(iosDriver, gmailUserInpt,gmailId);					
				WebElement gmailIdentifierNext = iosDriver.findElement(By.xpath("//div[@id='identifierNext']"));
				comnFunc.scrollToObject(iosDriver, gmailIdentifierNext);
				gmailIdentifierNext.click();							

// comnFunc.staticWait(4);
WebElement gmailPswdInpt = iosDriver.findElement(By.xpath("//input[@name=‘password’]"));
gmailPswdInpt.sendKeys(gmailPswd);
//comnFunc.sendKeysThroughJavaScript(iosDriver, gmailPswd, ExcelUtil.getMsiteGooglePassword());
WebElement gmailPswdNext = iosDriver.findElement(By.xpath(".//*[@id=‘passwordNext’]"));
comnFunc.scrollToObject(iosDriver, gmailPswdNext);
gmailPswdNext.click();
comnFunc.staticWait(10);
iosDriver.switchTo().window(hkWinHndl);
System.out.println(“Current Title after switch ::” + iosDriver.getTitle());
GlobalVar.test.log(LogStatus.INFO, “Switched to HK window…”);
System.out.println(“current window title :” + iosDriver.getTitle());
break;
}
catch(Exception e)
{
CommonFunctions.reportLogAndPrintInConsole(“Gmail Already logged in”);
break;
}
}
else if(iosDriver.getTitle().contains(“Error”)) {
System.out.println(“current window title :” + iosDriver.getTitle());
iosDriver.close();
break;
}
}
}

		//AccLoginPage.waitForGuestPageToBeInvisible();

// comnFunc.staticWait(5);
}


#3

For Pressing ‘Open’ button on this alert simply call context again with the native context id (NATIVE_APP) to leave the web frame.

// Click on gmail login link
driver.findElement(By.id(“ID of gmail login link”)).click();

// Automating the web view set context to WEBVIEW_1
driver.context(“WEBVIEW_1”);

driver.findElement(By.id(“ID of gmail username field”)).sendKeys("[email protected]");

driver.findElement(By.linkText(“Next”)).click();

driver.findElement(By.id(“ID of gmail password field”)).sendKeys(“password#18”);

driver.findElement(By.linkText(“Next”)).click();

// Set context to NATIVE_APP
driver.context(“NATIVE_APP”);

driver.findElement(lBy.id(“ID of gmail open button”)).click();