mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.2k stars 1.52k forks source link

Original error: adb error: secure_mkdirs failed: Permission denied #2027

Open zilvinas-t opened 2 years ago

zilvinas-t commented 2 years ago

System

Testcase

Hello. I'm trying to launch an automated test on firefox with these capabilities:

const firefoxOptions = {
    path: '/wd/hub',
    port: 4723,
    capabilities: {
        platformName: 'mac',
        browserName: 'firefox',
        "appium:automationName": 'Gecko',
        "appium:deviceName": "Pixel 4 API 30",
        "moz:firefoxOptions": {
            androidPackage: 'org.mozilla.firefox'
        },
    }
};

exports.firefoxOptions = firefoxOptions;

Stacktrace

Getting this error: Original error: adb error: secure_mkdirs failed: Permission denied Or sometimes this error occurs as well: Original error: adb error: couldn't create file: Permission denied

Stacktrace:

[W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"mac","browserName":"firefox","appium:automationName":"Gecko","appium:deviceName":"Pixel 4 API 30","moz:firefoxOptions":{"androidPackage":"org.mozilla.firefox"}},null,{"alwaysMatch":{"platformName":"mac","browserName":"firefox","appium:automationName":"Gecko","appium:deviceName":"Pixel 4 API 30","moz:firefoxOptions":{"androidPackage":"org.mozilla.firefox"}},"firstMatch":[{}]}]
[BaseDriver] Event 'newSessionRequested' logged at 1655819911590 (16:58:31 GMT+0300 (Eastern European Summer Time))
[Appium] Appium v1.22.3 creating new GeckoDriver (v0.3.3) session
[Appium] Applying relaxed security to 'GeckoDriver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
[BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[BaseDriver] Creating session with W3C capabilities: {
[BaseDriver]   "alwaysMatch": {
[BaseDriver]     "platformName": "mac",
[BaseDriver]     "browserName": "firefox",
[BaseDriver]     "moz:firefoxOptions": {
[BaseDriver]       "androidPackage": "org.mozilla.firefox"
[BaseDriver]     },
[BaseDriver]     "appium:automationName": "Gecko",
[BaseDriver]     "appium:deviceName": "Pixel 4 API 30"
[BaseDriver]   },
[BaseDriver]   "firstMatch": [
[BaseDriver]     {}
[BaseDriver]   ]
[BaseDriver] }
[BaseDriver] Session created with session id: 476be5e9-7d6b-4637-8c2f-9a5d8a555d9c
[GeckoDriverServer] Starting '/Users/zilvinastomkevicius/AndroidStudioProjects/autofill/gecko/geckodriver' with args ["-p",5200]
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:5200/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:5200
[GeckoDriverServer] [geckodriver] 1655819911608 geckodriver INFO    Listening on 127.0.0.1:5200
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:5200/status] with no body
[WD Proxy] Got response with status 200: {"value":{"message":"","ready":true}}
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:5200/session] with body: {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"browserName":"firefox","platformName":"mac","moz:firefoxOptions":{"androidPackage":"org.mozilla.firefox"}}}}
[GeckoDriverServer] [geckodriver] 1655819912659 mozdevice   INFO    Device is unrooted
[WD Proxy] Got response with status 500: {"value":{"error":"unknown error","message":"adb error: couldn't create file: Permission denied","stacktrace":""}}
[W3C] Matched W3C error code 'unknown error' to UnknownError
[GeckoDriver] Ending Gecko Driver session
[GeckoDriverServer] geckodriver has exited with code null, signal SIGTERM

Trace-level log

whimboo commented 2 years ago

@zilvinas-t thank you for the report. Could you maybe check again and have a look at the adb logcat? I wonder which file or folder cannot be created here given that the path is not visible in the error message. Did you also try to use a different storage option?

zilvinas-t commented 2 years ago

Hello, thank you for fast response. I attached a logcat.txt with logs catpured right after the error. Could elaborate more on storage option here? It says that it should not be used with versions later than 0.30.0. And if it should, I don't quite get how should I be doing it. Maybe there's an example?

whimboo commented 2 years ago

So there is not really something visible in the adb logcat. Could you maybe check where $EXTERNAL_STORAGE actually points to for your device? Run this command via adb shell echo $EXTERNAL_STORAGE.

Also I can see that you run your script through a WebDriver Proxy. Could you try to get rid of this extra layer and communicate with geckodriver directly? Our docs have some details in how run use eg. curl as client. Maybe there is a problem with that layer.

Regarding the storage option you can use it when you can start geckodriver directly like what I mentioned in the last paragraph. Just use the --android-storage option and test different values if maybe some other work.

zilvinas-t commented 2 years ago

Hello again. I've tried few things that you mentioned. appium:androidStorage returned 1656316695297 mozdevice INFO Device is unrooted when trying to launch with app or internal. By default the $EXTERNAL_STORAGE is sdcard.

Then I tried launching this url http://localhost:4444/session via Postman and it opened Firefox browser on my mac instead of opening it on Android emulator. Capabilities that I put in the request body looked like this:

{
    "path": "/wd/hub",
    "port": 4723,
    "capabilities": {
        "platformName": "mac",
        "browserName": "firefox",
        "appium:automationName": "Gecko",
        "appium:deviceName": "Pixel 4 API 30",
        "moz:firefoxOptions": {
            "androidPackage": "org.mozilla.firefox"
        }
    }
}

The response looked like this:

{
    "value": {
        "sessionId": "6bd0ed98-e21b-427d-8b3f-0a1ab934d304",
        "capabilities": {
            "acceptInsecureCerts": false,
            "browserName": "firefox",
            "browserVersion": "101.0.1",
            "moz:accessibilityChecks": false,
            "moz:buildID": "20220608170832",
            "moz:geckodriverVersion": "0.31.0",
            "moz:headless": false,
            "moz:processID": 19933,
            "moz:profile": "/var/folders/qq/frdqfwcd23b1jfwsl9r78tlw0000gn/T/rust_mozprofile5wUZki",
            "moz:shutdownTimeout": 60000,
            "moz:useNonSpecCompliantPointerOrigin": false,
            "moz:webdriverClick": true,
            "pageLoadStrategy": "normal",
            "platformName": "mac",
            "platformVersion": "21.5.0",
            "proxy": {},
            "setWindowRect": true,
            "strictFileInteractability": false,
            "timeouts": {
                "implicit": 0,
                "pageLoad": 300000,
                "script": 30000
            },
            "unhandledPromptBehavior": "dismiss and notify"
        }
    }
}

I also got these logs when the request was executed and browser was opened:

1656326026824   mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "--marionette" "-foreground" "-no-remote" "-profile" "/var/folders/qq/frdqfwcd23b1jfwsl9r78tlw0000gn/T/rust_mozprofile5wUZki"
2022-06-27 13:33:47.873 plugin-container[19935:263839] nil host used in call to allowsSpecificHTTPSCertificateForHost
2022-06-27 13:33:47.874 plugin-container[19935:263839] nil host used in call to allowsAnyHTTPSCertificateForHost:
1656326027890   Marionette  INFO    Marionette enabled
2022-06-27 13:33:47.918 plugin-container[19935:263839] nil host used in call to allowsSpecificHTTPSCertificateForHost
2022-06-27 13:33:47.918 plugin-container[19935:263839] nil host used in call to allowsAnyHTTPSCertificateForHost:
2022-06-27 13:33:47.919 plugin-container[19935:263844] nil host used in call to allowsSpecificHTTPSCertificateForHost
2022-06-27 13:33:47.919 plugin-container[19935:263844] nil host used in call to allowsAnyHTTPSCertificateForHost:
2022-06-27 13:33:49.092 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSButton: 0x125368c00>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2022-06-27 13:33:49.093 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSButton: 0x1254e5400>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2022-06-27 13:33:49.093 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSButton: 0x1254e0c00>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2022-06-27 13:33:49.094 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSButton: 0x1254e2c00>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2022-06-27 13:33:49.095 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSButton: 0x1254e5800>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2022-06-27 13:33:49.096 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSPopoverTouchBarItemButton: 0x1254e4400>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2022-06-27 13:33:49.097 firefox-bin[19933:263761] Warning: Expected min height of view: (<NSPopoverTouchBarItemButton: 0x11cbc6000>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at /var/folders/qq/frdqfwcd23b1jfwsl9r78tlw0000gn/T/rust_mozprofile5wUZki/search.json.mozlz4", (void 0)))
console.error: BackgroundUpdate: 
  _reasonsToNotScheduleUpdates: Failed to check for Maintenance Service Registry Key: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIUpdateProcessor.getServiceRegKeyExists]"  nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"  location: "JS frame :: resource://gre/modules/BackgroundUpdate.jsm :: _reasonsToNotScheduleUpdates :: line 241"  data: no]
1656326030832   Marionette  INFO    Listening on port 63743
Read port: 63743

The things I want to do is to open a sequence of websites on Firefox browser on Android emulator (or real device) and execute an automation script on each of one. I originally use NodeJS for it. Maybe there's something I'm missing or doing wrong?

whimboo commented 2 years ago

Yes, you miss firstMatch or alwaysMatch within the capabilities dict as given by the capability negotiation documentation.

zilvinas-t commented 2 years ago

Tried executing the request on these capabilites:

{
    "capabilities": {
        "alwaysMatch": {
            "browserName": "firefox",
            "platformName": "mac",
            "moz:firefoxOptions": {
                "androidPackage": "org.mozilla.firefox"
            },
            "appium:automationName": "Gecko",
            "appium:deviceName": "Pixel 4 API 30"
        },
        "firstMatch": [{}]
    }
}

Got an error response:

{
    "value": {
        "error": "unknown error",
        "message": "adb error: couldn't create file: Permission denied",
        "stacktrace": ""
    }
}

The geckodriver service prompted a log message: 1656398997577 mozdevice INFO Device is unrooted

Tried adding appium:androidStorage with internal, app and sdcard values and in all cases the error and the log was the same.

zilvinas-t commented 2 years ago

Hello, maybe there's an update regarding the issue? :)

zilvinas-t commented 2 years ago

Hello again, any updates? @whimboo

whimboo commented 2 years ago

@zilvinas-t sorry for the delay. As it looks like the right platform is selected now and geckodriver interacts with the Android device. Would you mind attaching the adb logcat and the full trace log of geckodriver?

zilvinas-t commented 2 years ago

Hello, thanks for your response.adblogcat.txt is here and talking about stacktrace, it just produces 1657719692270 mozdevice INFO Device is unrooted every time I execute the request in Postman.

alyasporty commented 1 year ago

@zilvinas-t I ran into the same issue and the way I solve it is after running adb connect run adb root and that should work after that