appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
373 stars 186 forks source link

How to switch from safari driver to iOS app driver? #83

Closed login4amit closed 9 years ago

login4amit commented 9 years ago

Hi Following is my scenario: We have web interface for which we had automation in selenium and C#(MS Test-Specflow). We have one iOS app for which we have written automation using appium + capabilities for iPad app. We are running automation from windows machine and with help of remote execution talking with appium server on Mac machine. Now in one of the scenario we need to click on button in web site which is launching that iOS app. This happens only if web site is open from iPad and safari browser. Once that app opened on UI user have to do some actions then at the end app will create one PDF and close that app, and application switches back to web interface with that PDF showing in UI. How to swiitch between safari browser and iOS app interface to automate this scenario.

Ex. Suppose In Gmail site there is one button to open Whatsapp. If user clicks on button whatsapp gets open. Then user perform action say send message to particular contact and once action is successful then system redirects user to gmail site. How to automate such scenario.

login4amit commented 9 years ago

@jlipps Any Comments.

Astro03 commented 9 years ago

@login4amit - i'm no expert but i'm almost positive you can't switch from one to another. I've actually never tried your con ops (concept of operations). I would assume if you use the iOS driver one from the beginning, it should work though. Try it out and let me know - i'm curious too since i've only used it with apps.

TikhomirovSergey commented 9 years ago

i'm no expert but i'm almost positive you can't switch from one to another.

I've never tried this. But I can advice this...

driver.Context = "NATIVE_APP";

I'am really not sure that it works...

@Astro03 What do you think about the enhancement on the server-side if client code above doesn't work with case described by @login4amit ?

login4amit commented 9 years ago

@Astro03 & @TikhomirovSergey Sure I will take a look at it and will get back to u soon. Thanks for the response.

talsurizon commented 7 years ago

i'm having the same problem, did you find a solution?

rutin31 commented 6 years ago

Hi, do you get any solution?

obstar commented 6 years ago

example of the code we use in our mobile framework

`public IDevice SwitchToNativeAppContext()
    {
        _driver.Context = "NATIVE_APP";
        return this;
    }

public IDevice SwitchToWebViewContext()
    {
        //wait until webview context load in app
        var i = 0;
        string context;
        while (true)
        {
            var contextList = _driver.Contexts.ToList();
            context = contextList.FirstOrDefault(c => c.Contains("WEBVIEW"));
            if (context != null)
                break;
            if (i >= 50) //wait up to 5 seconds to load webview
                throw new Exception("Could not find WEBVIEW context");

            Thread.Sleep(TimeSpan.FromMilliseconds(100)); //Maybe the view hasn't loaded yet
            i++;
        }

        _driver.Context = context;
        return this;
    }`
rutin31 commented 6 years ago

thank you very much I have to switch between two iOS apps what should I define on _driver.Context=?

obstar commented 6 years ago

I don't think its possible. Because when you start driver you're define app package and it can't be changed during same webdriver session.

rutin31 commented 6 years ago

I have the problem to get OTP when I do Swipe to notification the appium logs: [debug] [XCUITest] Connection to WDA timed out [debug] [iProxy] recv failed: Operation not permitted and C# error is: A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL ... The status of the exception was KeepAliveFailure, and the message was: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. I thought that there is a way to get otp from SMS app maybe you have any idea for this?