mykola-mokhnach / Appium-iOS-Inspector

Apache License 2.0
145 stars 60 forks source link

Appium session is unreachable despite the valid port #23

Closed darina-techery closed 7 years ago

darina-techery commented 7 years ago

Hi, I've pulled the latest version (Latest commit 10c4b83 on Apr 21), but no luck yet. I updated inspector.js with a valid port value and tried to open the page with my app launched in iOS Simulator, but all I see is "Appium session at http://127.0.0.1:21077/wd/hub is unreachable. Make sure your Appium test is running and click this message to retry."

Driver capabilities:

"networkConnectionEnabled" -> "false"
"orientation" -> "PORTRAIT"
"noReset" -> "true"
"databaseEnabled" -> "false"
"fullReset" -> "false"
"deviceName" -> "iPhone 6"
"CapabilityName" -> "driver.capabilities.IPhoneCapabilities"
"platform" -> "MAC"
"showXcodeLog" -> "true"
"defaultCapability" -> "false"
"newCommandTimeout" -> "0"
"platformVersion" -> "10.3.1"
"webStorageEnabled" -> "false"
"locationContextEnabled" -> "false"
"automationName" -> "XCUITest"
"browserName" -> 
"takesScreenshot" -> "true"
"waitForAppScript" -> "true"
"javascriptEnabled" -> "true"
"udid" -> "B2B986C8-69B3-4E84-88A8-893DD711A8F8"
"platformName" -> "iOS"
"autoAcceptAlerts" -> "false"```

UDID is also valid.

Server args: 0 = "/usr/local/lib/node_modules/appium/build/lib/main.js" 1 = "--port" 2 = "21077" 3 = "--address" 4 = "127.0.0.1" 5 = "--log-level" 6 = "error" 7 = "--bootstrap-port" 8 = "55974" 9 = "--tmp" 10 = "./target/tmp" 11 = "--local-timezone" 12 = "--session-override" 13 = "--log-timestamp"


Appium and its dependencies have the following versions (via npm):

├─┬ appium@1.6.5 │ ├─┬ appium-android-driver@1.20.0 │ │ ├─┬ appium-adb@2.23.0 │ │ ├─┬ appium-android-bootstrap@2.9.1 │ │ │ ├─┬ appium-uiautomator@1.1.1 │ │ ├── appium-android-ime@2.0.0 │ │ ├─┬ appium-chromedriver@2.11.2 │ │ ├── appium-unlock@0.1.1 │ │ ├── io.appium.settings@2.2.1 │ ├─┬ appium-base-driver@2.8.1 │ ├─┬ appium-fake-driver@0.1.11 │ ├─┬ appium-ios-driver@1.24.1 │ │ ├─┬ appium-ios-simulator@1.23.2 │ │ ├─┬ appium-remote-debugger@3.4.0 │ │ ├─┬ appium-xcode@3.2.2 │ ├─┬ appium-mac-driver@1.0.2 │ ├─┬ appium-selendroid-driver@1.6.2 │ ├─┬ appium-support@2.8.2 │ ├─┬ appium-uiautomator2-driver@0.3.3 │ │ ├── appium-uiautomator2-server@0.1.5 │ ├─┬ appium-windows-driver@0.5.0 │ ├─┬ appium-xcuitest-driver@2.30.0 │ ├── appium-youiengine-driver@1.0.11 ├─┬ appium-uiautomator2-driver@0.3.4 │ ├─┬ appium-adb@2.23.8 │ ├─┬ appium-android-driver@1.24.0 │ │ ├─┬ appium-android-bootstrap@2.9.1 │ │ │ ├── appium-uiautomator@1.1.1 │ │ ├── appium-android-ime@2.0.0 │ │ ├─┬ appium-chromedriver@2.12.0 │ │ ├── appium-unlock@0.1.1 │ │ ├── io.appium.settings@2.2.1 │ ├─┬ appium-base-driver@2.10.2 │ ├─┬ appium-support@2.8.2 │ ├── appium-uiautomator2-server@0.1.6 ├─┬ appium-xcuitest-driver@2.37.1 │ ├─┬ appium-base-driver@2.10.2 │ ├─┬ appium-ios-driver@1.25.0 │ │ ├─┬ appium-remote-debugger@3.5.0 │ ├─┬ appium-ios-simulator@1.24.1 │ ├─┬ appium-support@2.8.2 │ ├─┬ appium-xcode@3.3.0


What's weird: it worked last week and suddenly stopped working now.
Can it be a compatibility issue?
mykola-mokhnach commented 7 years ago

Is Appium really listening on that port? What is the output of netstat -an | grep 21077? Have you tried to execute Appium on the default port?

darina-techery commented 7 years ago

Yes, Appium is really listening on this port, it's assigned randlomly for each test session.

13:49:28.645 [main] INFO  (AppiumServiceProvider.java:38): Starting Appium service on port 21077

I use a simple java helper method to update inspector.js with this port and launch it:

public static void launchIOSInspector() {
        String browserName = "Google Chrome";
        String inspectorHtmlLocation = "{my local path}/Appium-iOS-Inspector/iOS%20Inspector.html";
        String inspectorConfiguration = "{my local path}/Appium-iOS-Inspector/iOS Inspector_files/inspector.js";

        List<String> content = new ArrayList<>();
        Path configPath = new File(inspectorConfiguration).toPath();
        try (BufferedReader reader = Files.newBufferedReader(configPath)) {
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.contains("APPIUM_ROOT")) {
                    content.add(line.replaceAll("127\\.0\\.0\\.1:\\d+", "127.0.0.1:" + DriverProvider.getAppiumPort()));
                } else {
                    content.add(line);
                }
            }
            reader.close();
        } catch (IOException x) {
            System.err.format("IOException: %s%n", x);
        }
        try (BufferedWriter writer = Files.newBufferedWriter(configPath)) {
            for (String line : content) {
                writer.write(line, 0, line.length());
                writer.newLine();
            }
            writer.close();
        } catch (IOException x) {
            System.err.format("IOException: %s%n", x);
        }
        String openInspectorCommand = "osascript -e 'tell application \""+browserName+"\"\n" +
                "  set myTab to make new tab at end of tabs of window 1\n" +
                "  set URL of myTab to \"file://"+inspectorHtmlLocation+"\"\n" +
                "  activate\n" +
                "end tell'";
        CMDUtils.executeCommand(openInspectorCommand);
    }
mykola-mokhnach commented 7 years ago

Maybe you try to open inspector too early when Appium session is still not ready? What do you see if you manually navigate to that url? Do you see the list of active sessions by adding /sessions suffix?

darina-techery commented 7 years ago

I've just launched it, and it worked... Nothing has changed in the environment and tests, only new Appium.app was installed. I'm sorry, but I really cannot tell what happened :( I can only say it's not the first time I experience this issue: inspector stops working at some point and goes back to life in a few days.

mykola-mokhnach commented 7 years ago

There is no magic there - we either have a connection to running Appium server and can connect to it or the server is not available and thus the error like the one above is shown. Closing as inspector-unrelated issue.