-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
3b2e16c
commit 12a14a2
Showing
42 changed files
with
1,632 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.chrome; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.remote.AdditionalHttpCommands; | ||
import org.openqa.selenium.remote.AugmenterProvider; | ||
import org.openqa.selenium.remote.CommandInfo; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import static org.openqa.selenium.remote.BrowserType.CHROME; | ||
|
||
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class}) | ||
public class AddHasCasting extends org.openqa.selenium.chromium.AddHasCasting { | ||
|
||
@Override | ||
public Map<String, CommandInfo> getAdditionalCommands() { | ||
return ImmutableMap.of( | ||
GET_CAST_SINKS, new CommandInfo("session/:sessionId/goog/cast/get_sinks", HttpMethod.GET), | ||
SET_CAST_SINK_TO_USE, new CommandInfo("session/:sessionId/goog/cast/set_sink_to_use", HttpMethod.POST), | ||
START_CAST_TAB_MIRRORING, new CommandInfo("session/:sessionId/goog/cast/start_tab_mirroring", HttpMethod.POST), | ||
GET_CAST_ISSUE_MESSAGE, new CommandInfo("session/:sessionId/goog/cast/get_issue_message", HttpMethod.GET), | ||
STOP_CASTING, new CommandInfo("session/:sessionId/goog/cast/stop_casting", HttpMethod.POST)); | ||
} | ||
|
||
@Override | ||
public Predicate<Capabilities> isApplicable() { | ||
return caps -> CHROME.equals(caps.getBrowserName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.chrome; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.remote.AdditionalHttpCommands; | ||
import org.openqa.selenium.remote.AugmenterProvider; | ||
import org.openqa.selenium.remote.CommandInfo; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import static org.openqa.selenium.remote.BrowserType.CHROME; | ||
|
||
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class}) | ||
public class AddHasCdp extends org.openqa.selenium.chromium.AddHasCdp { | ||
|
||
@Override | ||
public Map<String, CommandInfo> getAdditionalCommands() { | ||
return ImmutableMap.of( | ||
EXECUTE_CDP, new CommandInfo("session/:sessionId/goog/cdp/execute", HttpMethod.POST)); | ||
} | ||
|
||
@Override | ||
public Predicate<Capabilities> isApplicable() { | ||
return caps -> CHROME.equals(caps.getBrowserName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.chromium; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.internal.Require; | ||
import org.openqa.selenium.remote.AdditionalHttpCommands; | ||
import org.openqa.selenium.remote.AugmenterProvider; | ||
import org.openqa.selenium.remote.CommandInfo; | ||
import org.openqa.selenium.remote.ExecuteMethod; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
public abstract class AddHasCasting implements AugmenterProvider<HasCasting>, AdditionalHttpCommands { | ||
|
||
public static final String GET_CAST_SINKS = "getCastSinks"; | ||
public static final String SET_CAST_SINK_TO_USE = "selectCastSink"; | ||
public static final String START_CAST_TAB_MIRRORING = "startCastTabMirroring"; | ||
public static final String GET_CAST_ISSUE_MESSAGE = "getCastIssueMessage"; | ||
public static final String STOP_CASTING = "stopCasting"; | ||
|
||
@Override | ||
public abstract Map<String, CommandInfo> getAdditionalCommands(); | ||
|
||
@Override | ||
public abstract Predicate<Capabilities> isApplicable(); | ||
|
||
@Override | ||
public Class<HasCasting> getDescribedInterface() { | ||
return HasCasting.class; | ||
} | ||
|
||
@Override | ||
public HasCasting getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) { | ||
return new HasCasting() { | ||
@Override public List<Map<String, String>> getCastSinks() { | ||
return (List<Map<String, String>>) executeMethod.execute(GET_CAST_SINKS, null); | ||
} | ||
|
||
@Override public void selectCastSink(String deviceName) { | ||
Require.nonNull("Device Name", deviceName); | ||
|
||
executeMethod.execute(SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName)); | ||
} | ||
|
||
@Override public void startTabMirroring(String deviceName) { | ||
Require.nonNull("Device Name", deviceName); | ||
|
||
executeMethod.execute(START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName)); | ||
} | ||
|
||
@Override public String getCastIssueMessage() { | ||
return executeMethod.execute(GET_CAST_ISSUE_MESSAGE, null).toString(); | ||
} | ||
|
||
@Override public void stopCasting(String deviceName) { | ||
Require.nonNull("Device Name", deviceName); | ||
|
||
executeMethod.execute(STOP_CASTING, ImmutableMap.of("sinkName", deviceName)); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.chromium; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.internal.Require; | ||
import org.openqa.selenium.remote.AdditionalHttpCommands; | ||
import org.openqa.selenium.remote.AugmenterProvider; | ||
import org.openqa.selenium.remote.CommandInfo; | ||
import org.openqa.selenium.remote.ExecuteMethod; | ||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import static org.openqa.selenium.chromium.ChromiumDriver.KNOWN_CHROMIUM_BROWSERS; | ||
|
||
public abstract class AddHasCdp implements AugmenterProvider<HasCdp>, AdditionalHttpCommands { | ||
|
||
public static final String EXECUTE_CDP = "executeCdpCommand"; | ||
|
||
@Override | ||
public abstract Map<String, CommandInfo> getAdditionalCommands(); | ||
|
||
@Override | ||
public Predicate<Capabilities> isApplicable() { | ||
return caps -> KNOWN_CHROMIUM_BROWSERS.contains(caps.getBrowserName()); | ||
} | ||
|
||
@Override | ||
public Class<HasCdp> getDescribedInterface() { | ||
return HasCdp.class; | ||
} | ||
|
||
@Override | ||
public HasCdp getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) { | ||
return new HasCdp() { | ||
@Override | ||
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) { | ||
Require.nonNull("Command name", commandName); | ||
Require.nonNull("Parameters", parameters); | ||
|
||
Map<String, Object> toReturn = (Map<String, Object>) executeMethod.execute( | ||
EXECUTE_CDP, ImmutableMap.of("cmd", commandName, "params", parameters)); | ||
|
||
return ImmutableMap.copyOf(toReturn); | ||
} | ||
}; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
java/src/org/openqa/selenium/chromium/AddHasLaunchApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.chromium; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.internal.Require; | ||
import org.openqa.selenium.remote.AdditionalHttpCommands; | ||
import org.openqa.selenium.remote.AugmenterProvider; | ||
import org.openqa.selenium.remote.CommandInfo; | ||
import org.openqa.selenium.remote.ExecuteMethod; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import static org.openqa.selenium.chromium.ChromiumDriver.KNOWN_CHROMIUM_BROWSERS; | ||
|
||
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class}) | ||
public class AddHasLaunchApp implements AugmenterProvider<HasLaunchApp>, AdditionalHttpCommands { | ||
|
||
public static final String LAUNCH_APP = "launchApp"; | ||
|
||
private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of( | ||
LAUNCH_APP, new CommandInfo("/session/:sessionId/chromium/launch_app", HttpMethod.POST)); | ||
|
||
@Override | ||
public Map<String, CommandInfo> getAdditionalCommands() { | ||
return COMMANDS; | ||
} | ||
|
||
@Override | ||
public Predicate<Capabilities> isApplicable() { | ||
return caps -> KNOWN_CHROMIUM_BROWSERS.contains(caps.getBrowserName()); | ||
} | ||
|
||
@Override | ||
public Class<HasLaunchApp> getDescribedInterface() { | ||
return HasLaunchApp.class; | ||
} | ||
|
||
@Override | ||
public HasLaunchApp getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) { | ||
return new HasLaunchApp() { | ||
@Override | ||
public void launchApp(String id) { | ||
Require.nonNull("id of Chromium App", id); | ||
|
||
executeMethod.execute(LAUNCH_APP, ImmutableMap.of("id", id)); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.