Switch between WebView and NativeView with Swift

641 Views Asked by At

Problem Statement:

  1. I have an a native app which has a G+ single sign-on.
  2. When I click that button, it displays an alert - "application wants to use google.com to sign-in" along with 2 buttons "Continue" and "Cancel"
  3. When I press "Continue" on the alert, it opens a browser inside the app where the account selection page opens. It shows accounts.google.com as the page URL.
  4. Assuming that I've already signed in to Google once before, I want to select / click a particular account from the list of google accounts being displayed there.
  5. After I click the account, the user is navigated to a native screen called "Dashboard".

To automate this, in Appium + Java, I click on the G+ button and then switch the context to webview and then select the account using xpath and then switch back to native view as login is done now and application is back to the native screen.

driver.findElement(By.xpath("XPATH of Native Screen - Google SignIn Button")).click;

driver.switchTo().alert().accept();//Clicks "Continue" Button.

driver.context("WEBVIEW"); //Switch to WebView

driver.findElement(By.xpath("XPATH of intended Account Name HTML control")).click();

driver.context("NATIVEVIEW");

...Then, I perform the other operations that I want to perform on the native app screen.

I want to do the same in XCode + Swift but I'm not finding any way to do it.

Here's what I do

//some code to click on the button

app.buttons["Google Sign In"].tap() app.alerts["“AppName” Wants to Use “google.com” to Sign In"].buttons["Continue"].tap() ...Now I don't know how to switch to WebView of the App and click on the HTML control that contains the account name and then switch back to native view.

Please help.

1

There are 1 best solutions below

0
On

Try using this when you click on sign in with google:

GIDSignIn.sharedInstance().signOut()