Skip to content

Commit

Permalink
[CDP] Add inspector API (#7418)
Browse files Browse the repository at this point in the history
  • Loading branch information
dratler authored and shs96c committed Aug 1, 2019
1 parent 9c9661f commit 9e02de5
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.devtools.inspector;

import static org.openqa.selenium.devtools.ConverterFunctions.map;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;

@Beta
public class Inspector {

/** Enables inspector domain notifications. */
public static Command<Void> enable() {
return new Command<>("Inspector.enable", ImmutableMap.of());
}

/** Disables inspector domain notifications. */
public static Command<Void> disable() {
return new Command<>("Inspector.disable", ImmutableMap.of());
}
/** Fired when remote debugging connection is about to be terminated. Contains detach reason. */
public static Event<String> detached() {
return new Event<>("Inspector.detached", map("reason", String.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.devtools;

import static org.openqa.selenium.devtools.inspector.Inspector.detached;
import static org.openqa.selenium.devtools.inspector.Inspector.disable;
import static org.openqa.selenium.devtools.inspector.Inspector.enable;
import static org.openqa.selenium.devtools.target.Target.attachToTarget;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.devtools.target.Target;
import org.openqa.selenium.devtools.target.model.SessionId;
import org.openqa.selenium.devtools.target.model.TargetInfo;

import java.util.List;
import java.util.Optional;

public class ChromeDevToolsInspectorTest extends DevToolsTestBase {
@Test
public void inspectDetached() {
devTools.addListener(detached(), Assert::assertNotNull);
devTools.send(enable());
List<TargetInfo> targetInfos = devTools.send(Target.getTargets());
targetInfos.stream()
.forEach(
targetInfo -> {
SessionId sessionId =
devTools.send(attachToTarget(targetInfo.getTargetId(), Optional.of(false)));
devTools.send(
Target.sendMessageToTarget(
"{\"method\":\"Page.crash\"}",
Optional.of(sessionId),
Optional.of(targetInfo.getTargetId())));
});
devTools.send(disable());
}
}
19 changes: 9 additions & 10 deletions java/client/test/org/openqa/selenium/devtools/DevToolsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@

@RunWith(Suite.class)
@Suite.SuiteClasses({
ChromeDevToolsProfilerTest.class,
ChromeDevToolsTargetTest.class,
ChromeDevToolsNetworkTest.class,
ChromeDevToolsPerformanceTest.class,
ChromeDevToolsConsoleTest.class,
ChromeDevToolsLogTest.class,
ChromeDevToolsSecurityTest.class
ChromeDevToolsProfilerTest.class,
ChromeDevToolsTargetTest.class,
ChromeDevToolsNetworkTest.class,
ChromeDevToolsPerformanceTest.class,
ChromeDevToolsConsoleTest.class,
ChromeDevToolsLogTest.class,
ChromeDevToolsSecurityTest.class,
ChromeDevToolsInspectorTest.class
})
public class DevToolsTests {

}
public class DevToolsTests {}

0 comments on commit 9e02de5

Please sign in to comment.