question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No targets found, when switching from app to browser on iOS

See original GitHub issue

The problem

Sometimes you need to automate the following flow

  1. login to a native app
  2. after login you need to pay something and a link in the app opens a browser
  3. the browser needs to be used to pay
  4. after payment the browser is opening the app again
  5. the payment in the app is processed

This is currently failing at step 3 with the following error Encountered internal error running command: Error: No targets found, unable to communicate with device

Environment

  • Appium version (or git revision) that exhibits the issue: 1.14.0
  • ~Last Appium version that did not exhibit the issue (if applicable):~
  • Desktop OS/version used to run Appium: OSX Mojave
  • Node.js version (unless using Appium.app|exe): v10.15.2
  • Npm or Yarn package manager: npm
  • Mobile platform/version under test: iOS 12.2
  • Real device or emulator/simulator: sim
  • Appium CLI or Appium.app|exe: cli

Link to Appium logs

The logs can be found here

Code To Reproduce Issue [ Good To Have ]

I’m using WebdriverIO and the Sauce Labs sample app to execute the test, the test executes the following steps:

// config
config.capabilities = [
    {
        // The defaults you need to have in your config
        deviceName: 'iPhone X',
        platformName: 'iOS',
        platformVersion: '12.2',
        orientation: 'PORTRAIT',
        // The path to the app, see https://github.com/saucelabs/sample-app-mobile/releases
        app: join(process.cwd(), './apps/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.1.0.app.zip'),
        // Read the reset strategies very well, they differ per platform, see
        // http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
        noReset: true,
        newCommandTimeout: 240,
        maxInstances: 1,
        fullContextList: true,
    },
];
describe('Appium', () => {
    it('should be able to work with the browser that is opened with the app', () => {
        // Login to the app and verify that it succeeded
        LoginScreen.waitForIsShown();
        LoginScreen.signIn(LOGIN_USERS.STANDARD);
        InventoryListScreen.waitForIsShown();

        expect(InventoryListScreen.isShown()).toEqual(true);

        // Open the menu and click on the about screen
        Menu.open();
        Menu.openAbout();

        let webviewID = {};

        driver.waitUntil(() => {
            const contexts = Context.getCurrentContexts();
            webviewID = contexts
                .filter(context => {
                    console.log('filter context = ', context)
                    return !context.id.includes('NATIVE_APP')
                })
                .find(context => {
                    console.log('some context = ', context)
                    return context.url.includes('https://saucelabs.com/')
                });
            return webviewID || false;
        }, DEFAULT_TIMEOUT);

        driver.switchContext(webviewID.id);

        expect(browser.getTitle()).toEqual('Cross Browser Testing, Selenium Testing, Mobile Testing | Sauce Labs');
    })
})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
imurchiecommented, Sep 4, 2019

@wswebcreation Can you try the latest beta of Appium, and add the includeSafariInWebviews capability (set to true) to your desired caps for the test?

0reactions
wswebcreationcommented, Oct 3, 2019

Retested this with Appium 1.15.0-stable and it works like a charm, thanks for this!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't log in to Target app using iphone… - Apple Community
If so, try turning off VPN. Go to Settings/Safari and tap Clear History and Website Data. That will clear the cache.
Read more >
Mobile & app support - Target Help
On your iOS device, go to Settings, then Wi-Fi. Turn on your Wi-Fi connection if it's not already on. Browse the list of...
Read more >
Possible to open iPhone Safari and target a specific window?
What I noticed about Safari is that it won't open another tab if the page you are opening with openURL: is/was already open...
Read more >
Debugging Guide for Apps in iOS Safari and Android Chrome
The app preview may not automatically appear when you open Chrome Developer Tools due to a minor bug. To make it appear, click...
Read more >
iOS/iPadOS app protection policy settings - Microsoft Intune
Specify which iOS/iPadOS Universal Links should open in the specified managed application instead of the protected browser specified by the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found