Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute script do not have arguments #263

Closed
sinhpn92 opened this issue Sep 18, 2019 · 11 comments
Closed

Execute script do not have arguments #263

sinhpn92 opened this issue Sep 18, 2019 · 11 comments

Comments

@sinhpn92
Copy link

I'm try to execute script when test native mobile app.
On Python I do it:

${searchAction}  create dictionary  action  search
execute script  mobile:performEditorAction  ${searchAction}

But I got the error message: Keyword 'AppiumLibrary.Execute Script' expected 1 argument, got 2.

I see that in the applicationmanager file:

def execute_script(self, script):
        """
        Inject a snippet of JavaScript into the page for execution in the
        context of the currently selected frame (Web context only).

        The executed script is assumed to be synchronous and the result
        of evaluating the script is returned to the client.

        New in AppiumLibrary 1.5
        """

        return self._current_application().execute_script(script)

So, How do I execute script with arguments?

@serhatbolsu
Copy link
Owner

serhatbolsu commented Oct 3, 2019

can you try like this?
execute script mobile:performEditorAction "action: search"

@TencolHu
Copy link

TencolHu commented Oct 18, 2019

I also got this problem when try robot command as below:
execute script mobile:performEditorAction "action: search"

also get this error:

WebDriverException: Message: Unknown mobile command "performEditorAction "action: search"". Only shell,scrollBackTo,viewportScreenshot,deepLink,startLogsBroadcast,stopLogsBroadcast,acceptAlert,dismissAlert,batteryInfo,deviceInfo,changePermissions,getPermissions,performEditorAction commands are supported.

please help me check how to execute script with arguments, thank you

@paparent
Copy link

This is why I proposed execute_adb_shell, because execute_scrip accepts only one argument and doesn't pass the rest to Selenium.

@TencolHu
Copy link

My short-term solution is to call appium server via api command:
And it worked now.
POST: https://<appium server ip>:4723/session/<session_id>/execute
{ "script":"mobile:performEditorAction", "args": [{"action":"search"}] }

@simplezhang1990
Copy link

@TencolHu could you give me detail introduction about your solution, I don't know how to call the appium server via api command

@TencolHu
Copy link

TencolHu commented Nov 18, 2019

@simplezhang1990

  1. First you should know which library for http request on your code.
    ex: Python should use requests library to implement api [Get , POST, PUT..]
  2. Start appium server on you local machine, ip would be : 127.0.0.1 or your server ip, port : 4723
  3. Use HTTP requests library to call execute api [Method: POST]
    you can refer appium api:
    http://appium.io/docs/en/about-appium/api/

Method: POST
get session id by appium library, below args is to trigger search like search key on virtual keyboard

URL : https://127.0.0.1:4001/session/{session_id}/execute
Body
{
"script":"mobile:performEditorAction",
"args": [{"action":"search"}]
}

for the Android mobile: here are some commands for use, please check below link:
http://appium.io/docs/en/commands/mobile-command/index.html

@nixuewei
Copy link

nixuewei commented Apr 7, 2021

    ${current_session_id}    Get Appium SessionId
    Call Appium API    ${current_session_id}
Call Appium API
    [Arguments]    ${session_id}
    [Documentation]    Call Appium API
    ${header}    Create Dictionary    Content-Type=application/json;charset=UTF-8
    Create Session    website    url=http://127.0.0.1:4723    verify=False
    ${response}    Post Request    website    /wd/hub/session/${session_id}/execute    headers=${header}    data={"script":"mobile:performEditorAction","args":[{"action":"search"}]}
    ${root}    To Json    ${response.content}
    Delete All Sessions

I works with above code

@serhatbolsu
Copy link
Owner

@paparent can you give guys an example?
#265 has implemented execute_adb_shell can you check it

@paparent
Copy link

@serhatbolsu you can for example execute command from: https://developer.android.com/studio/command-line/adb

execute adb shell am broadcast ...

@SiNeumann
Copy link

@serhatbolsu anyone working on this? I would have a look.

@serhatbolsu
Copy link
Owner

serhatbolsu commented Oct 26, 2022

fixed with #363 , please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants