Skip to content

Commit 3fd3bac

Browse files
feat: Add Windows driver options (#1564)
1 parent 853ef49 commit 3fd3bac

15 files changed

+611
-7
lines changed

src/main/java/io/appium/java_client/android/options/app/ActivityOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.appium.java_client.android.options.app;
1818

19-
import io.appium.java_client.android.options.BaseMapOptionData;
19+
import io.appium.java_client.remote.options.BaseMapOptionData;
2020

2121
import java.util.Map;
2222
import java.util.Optional;

src/main/java/io/appium/java_client/android/options/app/IntentOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.appium.java_client.android.options.app;
1818

19-
import io.appium.java_client.android.options.BaseMapOptionData;
19+
import io.appium.java_client.remote.options.BaseMapOptionData;
2020

2121
import java.util.List;
2222
import java.util.Map;

src/main/java/io/appium/java_client/android/options/localization/AppLocale.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
package io.appium.java_client.android.options.localization;
1818

19-
import io.appium.java_client.android.options.BaseMapOptionData;
19+
import io.appium.java_client.remote.options.BaseMapOptionData;
2020

21-
import java.util.Collections;
22-
import java.util.HashMap;
2321
import java.util.Map;
2422
import java.util.Optional;
2523

src/main/java/io/appium/java_client/android/options/BaseMapOptionData.java renamed to src/main/java/io/appium/java_client/remote/options/BaseMapOptionData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.appium.java_client.android.options;
17+
package io.appium.java_client.remote.options;
1818

1919
import com.google.gson.GsonBuilder;
2020

@@ -24,7 +24,7 @@
2424
import java.util.Optional;
2525

2626
public abstract class BaseMapOptionData<T extends BaseMapOptionData<T>> {
27-
protected Map<String, Object> options;
27+
private Map<String, Object> options;
2828

2929
public BaseMapOptionData() {
3030
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
17+
package io.appium.java_client.windows.options;
18+
19+
import io.appium.java_client.remote.options.BaseMapOptionData;
20+
21+
import java.util.Map;
22+
import java.util.Optional;
23+
24+
public class RunScript extends BaseMapOptionData<RunScript> {
25+
public RunScript() {
26+
}
27+
28+
public RunScript(Map<String, Object> options) {
29+
super(options);
30+
}
31+
32+
/**
33+
* Allows to provide a multiline PowerShell script.
34+
*
35+
* @param script A valid PowerShell script.
36+
* @return self instance for chaining.
37+
*/
38+
public RunScript withScript(String script) {
39+
return assignOptionValue("script", script);
40+
}
41+
42+
/**
43+
* Get a multiline PowerShell script.
44+
*
45+
* @return PowerShell script.
46+
*/
47+
public Optional<String> getScript() {
48+
return getOptionValue("script");
49+
}
50+
51+
/**
52+
* Allows to provide a single-line PowerShell script.
53+
*
54+
* @param command A valid PowerShell script.
55+
* @return self instance for chaining.
56+
*/
57+
public RunScript withCommand(String command) {
58+
return assignOptionValue("command", command);
59+
}
60+
61+
/**
62+
* Get a single-line PowerShell script.
63+
*
64+
* @return PowerShell script.
65+
*/
66+
public Optional<String> getCommand() {
67+
return getOptionValue("command");
68+
}
69+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
17+
package io.appium.java_client.windows.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.net.URL;
24+
import java.util.Optional;
25+
26+
public interface SupportsAppArgumentsOption<T extends BaseOptions<T>> extends
27+
Capabilities, CanSetCapability<T> {
28+
String APP_ARGUMENTS_OPTION = "appArguments";
29+
30+
/**
31+
* Application arguments string.
32+
*
33+
* @param args E.g. "/?"
34+
* @return self instance for chaining.
35+
*/
36+
default T setAppArguments(String args) {
37+
return amend(APP_ARGUMENTS_OPTION, args);
38+
}
39+
40+
/**
41+
* Get application arguments.
42+
*
43+
* @return Application arguments.
44+
*/
45+
default Optional<String> setAppArguments() {
46+
return Optional.ofNullable((String) getCapability(APP_ARGUMENTS_OPTION));
47+
}
48+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
17+
package io.appium.java_client.windows.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
public interface SupportsAppTopLevelWindowOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String APP_TOP_LEVEL_WINDOW_OPTION = "appTopLevelWindow";
28+
29+
/**
30+
* Set the hexadecimal handle of an existing application top level
31+
* window to attach to, for example 0x12345 (should be of string type).
32+
* Either this capability or app one must be provided on session startup.
33+
*
34+
* @param identifier E.g. "0x12345".
35+
* @return self instance for chaining.
36+
*/
37+
default T setAppTopLevelWindow(String identifier) {
38+
return amend(APP_TOP_LEVEL_WINDOW_OPTION, identifier);
39+
}
40+
41+
/**
42+
* Get the hexadecimal handle of an existing application top level
43+
* window to attach to.
44+
*
45+
* @return Top level window handle.
46+
*/
47+
default Optional<String> getAppTopLevelWindow() {
48+
return Optional.ofNullable((String) getCapability(APP_TOP_LEVEL_WINDOW_OPTION));
49+
}
50+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
17+
package io.appium.java_client.windows.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
public interface SupportsAppWorkingDirOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String APP_WORKING_DIR_OPTION = "appWorkingDir";
28+
29+
/**
30+
* Full path to the folder, which is going to be set as the working
31+
* dir for the application under test. This is only applicable for classic apps.
32+
*
33+
* @param path Existing folder path on the server file system.
34+
* @return self instance for chaining.
35+
*/
36+
default T setAppWorkingDir(String path) {
37+
return amend(APP_WORKING_DIR_OPTION, path);
38+
}
39+
40+
/**
41+
* Get the full path to the folder, which is going to be set as the working
42+
* dir for the application under test.
43+
*
44+
* @return Folder path on the server file system.
45+
*/
46+
default Optional<String> getAppWorkingDir() {
47+
return Optional.ofNullable((String) getCapability(APP_WORKING_DIR_OPTION));
48+
}
49+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
17+
package io.appium.java_client.windows.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.time.Duration;
24+
import java.util.Optional;
25+
26+
import static io.appium.java_client.internal.CapabilityHelpers.toDuration;
27+
28+
public interface SupportsCreateSessionTimeoutOption<T extends BaseOptions<T>> extends
29+
Capabilities, CanSetCapability<T> {
30+
String CREATE_SESSION_TIMEOUT_OPTION = "createSessionTimeout";
31+
32+
/**
33+
* Set the timeout used to retry Appium Windows Driver session startup.
34+
* This capability could be used as a workaround for the long startup times
35+
* of UWP applications (aka Failed to locate opened application window
36+
* with appId: TestCompany.my_app4!App, and processId: 8480). Default value is 20000ms.
37+
*
38+
* @param timeout The timeout value.
39+
* @return self instance for chaining.
40+
*/
41+
default T setCreateSessionTimeout(Duration timeout) {
42+
return amend(CREATE_SESSION_TIMEOUT_OPTION, timeout.toMillis());
43+
}
44+
45+
/**
46+
* Get the timeout used to retry Appium Windows Driver session startup.
47+
*
48+
* @return The timeout value.
49+
*/
50+
default Optional<Duration> getCreateSessionTimeout() {
51+
return Optional.ofNullable(
52+
toDuration(getCapability(CREATE_SESSION_TIMEOUT_OPTION))
53+
);
54+
}
55+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
17+
package io.appium.java_client.windows.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsMsExperimentalWebDriverOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String MS_EXPERIMENTAL_WEBDRIVER_OPTION = "ms:experimental-webdriver";
30+
31+
/**
32+
* Enforce to enable experimental driver features and optimizations.
33+
*
34+
* @return self instance for chaining.
35+
*/
36+
default T experimentalWebDriver() {
37+
return amend(MS_EXPERIMENTAL_WEBDRIVER_OPTION, true);
38+
}
39+
40+
/**
41+
* Enables experimental features and optimizations. See Appium Windows
42+
* Driver release notes for more details on this capability. false by default.
43+
*
44+
* @param value Whether to enable experimental features and optimizations.
45+
* @return self instance for chaining.
46+
*/
47+
default T setExperimentalWebDriver(boolean value) {
48+
return amend(MS_EXPERIMENTAL_WEBDRIVER_OPTION, value);
49+
}
50+
51+
/**
52+
* Get whether to enable experimental features and optimizations.
53+
*
54+
* @return True or false.
55+
*/
56+
default Optional<Boolean> isExperimentalWebDriver() {
57+
return Optional.ofNullable(toSafeBoolean(getCapability(MS_EXPERIMENTAL_WEBDRIVER_OPTION)));
58+
}
59+
}

0 commit comments

Comments
 (0)