mcdcorp / opentest

Open source test automation tool for web applications, mobile apps and APIs
https://getopentest.org
MIT License
447 stars 107 forks source link

Automation issue #544

Closed namedna closed 2 years ago

namedna commented 2 years ago

Hi, can you show me how to executeScript "mobile:launchApp" on your OpenTest? I need to use it to launch iOS app. We used to use “action: org.getopentest.appium.LaunchApp” but now this not working anymore. I need to change to executeScript mobile:launchApp. Followed this doc but don't know how to use it. https://github.com/appium/appium-xcuitest-driver#mobile-launchapp

This is pretty urgent. We are blocked from running our script.

adrianth commented 2 years ago

This feature will be present in the next release, but if you need a solution urgently, the best way forward is to create a custom keyword. Here's the code for it:

package custom;

import java.util.Map;
import org.getopentest.appium.core.AppiumTestAction;

public class ExecuteScript extends AppiumTestAction {

    @Override
    public void run() {
        String script = this.readStringArgument("script");
        Map<String, Object> scriptArgs = this.readMapArgument("scriptArgs", null);

        Object result = this.driver.executeScript(script, scriptArgs);

        this.writeOutput("result", result);
    }
}

Save this as ExecuteScript.java in a new Java project and add a dependency on the opentest-appium project (that's where the AppiumTestAction class resides). Then, compile it into a JAR file and drop the JAR file into the user-jars directory of your test actor. You can find the step by step instructions in this tutorial.

Once that's done, you can start using the new keyword in your test:

- description: Run script
  action: custom.ExecuteScript  
  args:
    script: "mobile: launchApp"
    scriptArgs:
      bundleId: <your.bundle.id>
namedna commented 2 years ago

Hi, Thanks for your response. I will try this with my team.

adrianth commented 2 years ago

@namedna Please note that I managed to publish the ExecuteScript keyword las week with OpenTest version 1.3.8 (currently in beta). You can use version 1.3.8 with this command: npm install opentest@beta -g. The keyword is not tested and I would appreciate any feedback you can provide on whether it is working as expected and any improvements that might be necessary. Once you have installed version 1.3.8 you can use the new keyword like this:

- description: Run script
  action: org.getopentest.appium.ExecuteScript  
  args:
    script: "mobile: launchApp"
    scriptArgs:
      bundleId: <your.bundle.id>
namedna commented 2 years ago

Hi, This beta solution works well as expected. We now can launch our application. Let us check some more rounds whether any issue. Thanks so much for your support!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.