How to use executeDriverScript method of io.appium.java_client.ExecutesDriverScript class

Best io.appium code snippet using io.appium.java_client.ExecutesDriverScript.executeDriverScript

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ExecutesDriverScript.java

Source: ExecutesDriverScript.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client;
18
19import io.appium.java_client.driverscripts.ScriptOptions;
20import io.appium.java_client.driverscripts.ScriptValue;
21import org.openqa.selenium.remote.Response;
22
23import javax.annotation.Nullable;
24import java.util.HashMap;
25import java.util.Map;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28import static io.appium.java_client.MobileCommand.EXECUTE_DRIVER_SCRIPT;
29
30public interface ExecutesDriverScript extends ExecutesMethod {
31
32    /**
33     * Run a set of scripts in scope of the current session.
34     * This allows multiple web driver commands to be executed within one request
35     * and may significantly speed up the automation script performance in
36     * distributed client-server environments with high latency.
37     * Read http://appium.io/docs/en/commands/session/execute-driver for more details.
38     *
39     * @since Appium 1.14
40     * @param script the web driver script to execute (it should
41     *               be a valid webdriverio code snippet by default
42     *               unless another option is provided)
43     * @param options additional scripting options
44     * @return The script result
45     * @throws org.openqa.selenium.WebDriverException if there was a failure while executing the script
46     */
47    default ScriptValue executeDriverScript(String script, @Nullable ScriptOptions options) {
48        Map<String, Object> data = new HashMap<>();
49        data.put("script", checkNotNull(script));
50        if (options != null) {
51            data.putAll(options.build());
52        }
53        Response response = execute(EXECUTE_DRIVER_SCRIPT, data);
54        //noinspection unchecked
55        Map<String, Object> value = (Map<String, Object>) response.getValue();
56        //noinspection unchecked
57        return new ScriptValue(value.get("result"), (Map<String, Object>) value.get("logs"));
58    }
59
60    /**
61     * Run a set of scripts in scope of the current session with default options.
62     *
63     * @since Appium 1.14
64     * @param script the web driver script to execute (it should
65     *               be a valid webdriverio code snippet)
66     * @return The script result
67     */
68    default ScriptValue executeDriverScript(String script) {
69        return executeDriverScript(script, null);
70    }
71}
72
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in ExecutesDriverScript

Trigger executeDriverScript code on LambdaTest Cloud Grid

Execute automation tests with executeDriverScript on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)