Skip to content

Commit 12a14a2

Browse files
authored
Create interfaces for RemoteWebDriver to use with Augmenter (#9856)
* Implement Network Conditions for Chromium both local and remote drivers * Allow Chromium casting functionality to be augmented by RemoteWebDriver * Allow Chromium cdp functionality to be augmented by RemoteWebDriver * Implement Safari permission endpoint and make accessible to RemoteWebDriver via Augmenter * Implement Safari attach debugger endpoint and make accessible to RemoteWebDriver via Augmenter * Allow Chromium permissions functionality to be augmented by RemoteWebDriver * Allow Chromium launch app functionality to be augmented by RemoteWebDriver
1 parent 3b2e16c commit 12a14a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1632
-188
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.chrome;
19+
20+
import com.google.auto.service.AutoService;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.openqa.selenium.Capabilities;
23+
import org.openqa.selenium.remote.AdditionalHttpCommands;
24+
import org.openqa.selenium.remote.AugmenterProvider;
25+
import org.openqa.selenium.remote.CommandInfo;
26+
import org.openqa.selenium.remote.http.HttpMethod;
27+
28+
import java.util.Map;
29+
import java.util.function.Predicate;
30+
31+
import static org.openqa.selenium.remote.BrowserType.CHROME;
32+
33+
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})
34+
public class AddHasCasting extends org.openqa.selenium.chromium.AddHasCasting {
35+
36+
@Override
37+
public Map<String, CommandInfo> getAdditionalCommands() {
38+
return ImmutableMap.of(
39+
GET_CAST_SINKS, new CommandInfo("session/:sessionId/goog/cast/get_sinks", HttpMethod.GET),
40+
SET_CAST_SINK_TO_USE, new CommandInfo("session/:sessionId/goog/cast/set_sink_to_use", HttpMethod.POST),
41+
START_CAST_TAB_MIRRORING, new CommandInfo("session/:sessionId/goog/cast/start_tab_mirroring", HttpMethod.POST),
42+
GET_CAST_ISSUE_MESSAGE, new CommandInfo("session/:sessionId/goog/cast/get_issue_message", HttpMethod.GET),
43+
STOP_CASTING, new CommandInfo("session/:sessionId/goog/cast/stop_casting", HttpMethod.POST));
44+
}
45+
46+
@Override
47+
public Predicate<Capabilities> isApplicable() {
48+
return caps -> CHROME.equals(caps.getBrowserName());
49+
}
50+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.chrome;
19+
20+
import com.google.auto.service.AutoService;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.openqa.selenium.Capabilities;
23+
import org.openqa.selenium.remote.AdditionalHttpCommands;
24+
import org.openqa.selenium.remote.AugmenterProvider;
25+
import org.openqa.selenium.remote.CommandInfo;
26+
import org.openqa.selenium.remote.http.HttpMethod;
27+
28+
import java.util.Map;
29+
import java.util.function.Predicate;
30+
31+
import static org.openqa.selenium.remote.BrowserType.CHROME;
32+
33+
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})
34+
public class AddHasCdp extends org.openqa.selenium.chromium.AddHasCdp {
35+
36+
@Override
37+
public Map<String, CommandInfo> getAdditionalCommands() {
38+
return ImmutableMap.of(
39+
EXECUTE_CDP, new CommandInfo("session/:sessionId/goog/cdp/execute", HttpMethod.POST));
40+
}
41+
42+
@Override
43+
public Predicate<Capabilities> isApplicable() {
44+
return caps -> CHROME.equals(caps.getBrowserName());
45+
}
46+
}

java/src/org/openqa/selenium/chrome/ChromeDriver.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717

1818
package org.openqa.selenium.chrome;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import org.openqa.selenium.Capabilities;
2122
import org.openqa.selenium.WebDriver;
2223
import org.openqa.selenium.chromium.ChromiumDriver;
2324
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
25+
import org.openqa.selenium.remote.CommandInfo;
2426
import org.openqa.selenium.remote.RemoteWebDriver;
27+
import org.openqa.selenium.remote.service.DriverService;
28+
29+
import java.util.Map;
2530

2631
/**
2732
* A {@link WebDriver} implementation that controls a Chrome browser running on the local machine.
@@ -96,7 +101,21 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
96101
*/
97102
@Deprecated
98103
public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {
99-
super(new ChromiumDriverCommandExecutor("goog", service), capabilities, ChromeOptions.CAPABILITY);
104+
super(new ChromeDriverCommandExecutor(service), capabilities, ChromeOptions.CAPABILITY);
105+
casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
106+
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
100107
}
101108

109+
private static class ChromeDriverCommandExecutor extends ChromiumDriverCommandExecutor {
110+
public ChromeDriverCommandExecutor(DriverService service) {
111+
super(service, getExtraCommands());
112+
}
113+
114+
private static Map<String, CommandInfo> getExtraCommands() {
115+
return ImmutableMap.<String, CommandInfo>builder()
116+
.putAll(new AddHasCasting().getAdditionalCommands())
117+
.putAll(new AddHasCdp().getAdditionalCommands())
118+
.build();
119+
}
120+
}
102121
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.chromium;
19+
20+
import com.google.common.collect.ImmutableMap;
21+
import org.openqa.selenium.Capabilities;
22+
import org.openqa.selenium.internal.Require;
23+
import org.openqa.selenium.remote.AdditionalHttpCommands;
24+
import org.openqa.selenium.remote.AugmenterProvider;
25+
import org.openqa.selenium.remote.CommandInfo;
26+
import org.openqa.selenium.remote.ExecuteMethod;
27+
28+
import java.util.List;
29+
import java.util.Map;
30+
import java.util.function.Predicate;
31+
32+
public abstract class AddHasCasting implements AugmenterProvider<HasCasting>, AdditionalHttpCommands {
33+
34+
public static final String GET_CAST_SINKS = "getCastSinks";
35+
public static final String SET_CAST_SINK_TO_USE = "selectCastSink";
36+
public static final String START_CAST_TAB_MIRRORING = "startCastTabMirroring";
37+
public static final String GET_CAST_ISSUE_MESSAGE = "getCastIssueMessage";
38+
public static final String STOP_CASTING = "stopCasting";
39+
40+
@Override
41+
public abstract Map<String, CommandInfo> getAdditionalCommands();
42+
43+
@Override
44+
public abstract Predicate<Capabilities> isApplicable();
45+
46+
@Override
47+
public Class<HasCasting> getDescribedInterface() {
48+
return HasCasting.class;
49+
}
50+
51+
@Override
52+
public HasCasting getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
53+
return new HasCasting() {
54+
@Override public List<Map<String, String>> getCastSinks() {
55+
return (List<Map<String, String>>) executeMethod.execute(GET_CAST_SINKS, null);
56+
}
57+
58+
@Override public void selectCastSink(String deviceName) {
59+
Require.nonNull("Device Name", deviceName);
60+
61+
executeMethod.execute(SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));
62+
}
63+
64+
@Override public void startTabMirroring(String deviceName) {
65+
Require.nonNull("Device Name", deviceName);
66+
67+
executeMethod.execute(START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName));
68+
}
69+
70+
@Override public String getCastIssueMessage() {
71+
return executeMethod.execute(GET_CAST_ISSUE_MESSAGE, null).toString();
72+
}
73+
74+
@Override public void stopCasting(String deviceName) {
75+
Require.nonNull("Device Name", deviceName);
76+
77+
executeMethod.execute(STOP_CASTING, ImmutableMap.of("sinkName", deviceName));
78+
}
79+
};
80+
}
81+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.chromium;
19+
20+
import com.google.common.collect.ImmutableMap;
21+
import org.openqa.selenium.Capabilities;
22+
import org.openqa.selenium.internal.Require;
23+
import org.openqa.selenium.remote.AdditionalHttpCommands;
24+
import org.openqa.selenium.remote.AugmenterProvider;
25+
import org.openqa.selenium.remote.CommandInfo;
26+
import org.openqa.selenium.remote.ExecuteMethod;
27+
28+
import java.util.Map;
29+
import java.util.function.Predicate;
30+
31+
import static org.openqa.selenium.chromium.ChromiumDriver.KNOWN_CHROMIUM_BROWSERS;
32+
33+
public abstract class AddHasCdp implements AugmenterProvider<HasCdp>, AdditionalHttpCommands {
34+
35+
public static final String EXECUTE_CDP = "executeCdpCommand";
36+
37+
@Override
38+
public abstract Map<String, CommandInfo> getAdditionalCommands();
39+
40+
@Override
41+
public Predicate<Capabilities> isApplicable() {
42+
return caps -> KNOWN_CHROMIUM_BROWSERS.contains(caps.getBrowserName());
43+
}
44+
45+
@Override
46+
public Class<HasCdp> getDescribedInterface() {
47+
return HasCdp.class;
48+
}
49+
50+
@Override
51+
public HasCdp getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
52+
return new HasCdp() {
53+
@Override
54+
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {
55+
Require.nonNull("Command name", commandName);
56+
Require.nonNull("Parameters", parameters);
57+
58+
Map<String, Object> toReturn = (Map<String, Object>) executeMethod.execute(
59+
EXECUTE_CDP, ImmutableMap.of("cmd", commandName, "params", parameters));
60+
61+
return ImmutableMap.copyOf(toReturn);
62+
}
63+
};
64+
}
65+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.chromium;
19+
20+
import com.google.auto.service.AutoService;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.openqa.selenium.Capabilities;
23+
import org.openqa.selenium.internal.Require;
24+
import org.openqa.selenium.remote.AdditionalHttpCommands;
25+
import org.openqa.selenium.remote.AugmenterProvider;
26+
import org.openqa.selenium.remote.CommandInfo;
27+
import org.openqa.selenium.remote.ExecuteMethod;
28+
import org.openqa.selenium.remote.http.HttpMethod;
29+
30+
import java.util.Map;
31+
import java.util.function.Predicate;
32+
33+
import static org.openqa.selenium.chromium.ChromiumDriver.KNOWN_CHROMIUM_BROWSERS;
34+
35+
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})
36+
public class AddHasLaunchApp implements AugmenterProvider<HasLaunchApp>, AdditionalHttpCommands {
37+
38+
public static final String LAUNCH_APP = "launchApp";
39+
40+
private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of(
41+
LAUNCH_APP, new CommandInfo("/session/:sessionId/chromium/launch_app", HttpMethod.POST));
42+
43+
@Override
44+
public Map<String, CommandInfo> getAdditionalCommands() {
45+
return COMMANDS;
46+
}
47+
48+
@Override
49+
public Predicate<Capabilities> isApplicable() {
50+
return caps -> KNOWN_CHROMIUM_BROWSERS.contains(caps.getBrowserName());
51+
}
52+
53+
@Override
54+
public Class<HasLaunchApp> getDescribedInterface() {
55+
return HasLaunchApp.class;
56+
}
57+
58+
@Override
59+
public HasLaunchApp getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
60+
return new HasLaunchApp() {
61+
@Override
62+
public void launchApp(String id) {
63+
Require.nonNull("id of Chromium App", id);
64+
65+
executeMethod.execute(LAUNCH_APP, ImmutableMap.of("id", id));
66+
}
67+
};
68+
}
69+
}

0 commit comments

Comments
 (0)