Skip to content

Commit 6f76368

Browse files
committed
Add initial examples
1 parent 7f4cf00 commit 6f76368

File tree

5 files changed

+76
-71
lines changed

5 files changed

+76
-71
lines changed

cdtp-examples/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.github.kklisura.cdpt.examples</groupId>
6+
<artifactId>cdtp-examples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>cdtp-examples</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.github.kklisura.cdtp</groupId>
22+
<artifactId>cdtp-java-client</artifactId>
23+
<version>1.0-SNAPSHOT</version>
24+
</dependency>
25+
</dependencies>
26+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.github.kklisura.cdpt.examples;
2+
3+
import com.github.kklisura.cdtp.launch.ChromeLauncher;
4+
import com.github.kklisura.cdtp.protocol.commands.Page;
5+
import com.github.kklisura.cdtp.services.ChromeDevToolsService;
6+
import com.github.kklisura.cdtp.services.ChromeService;
7+
import com.github.kklisura.cdtp.services.types.ChromeTab;
8+
9+
/**
10+
* Simple navigate-to-url example with DevTools Protocol java client.
11+
*
12+
* The following example with open chrome, create a tab with about:blank url and then navigate to
13+
* github.com. It will then wait 2seconds and it will navigate to twitter.com. It will again wait
14+
* for 2seconds and on the end it will close the tab and close the browser.
15+
*
16+
* @author Kenan Klisura
17+
*/
18+
public class SimpleNavigateToUrlExample {
19+
public static void main(String[] args) throws InterruptedException {
20+
// Create chrome launcher.
21+
try (final ChromeLauncher launcher = new ChromeLauncher()) {
22+
// Launch chrome either as headless (true) or regular (false).
23+
final ChromeService chromeService = launcher.launch(false);
24+
25+
// Create empty tab ie about:blank.
26+
final ChromeTab tab = chromeService.createTab();
27+
28+
// Get DevTools service to this tab
29+
try (final ChromeDevToolsService devToolsService = chromeService.createDevToolsService(tab)) {
30+
final Page page = devToolsService.getPage();
31+
32+
// Navigate to github.com.
33+
page.navigate("http://github.com");
34+
35+
// Wait a while...
36+
Thread.sleep(2000);
37+
38+
// Navigate to twitter.com.
39+
page.navigate("http://twitter.com");
40+
41+
// Wait a while...
42+
Thread.sleep(2000);
43+
}
44+
45+
// Close the tab.
46+
chromeService.closeTab(tab);
47+
}
48+
}
49+
}

cdtp-java-client/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<groupId>ch.qos.logback</groupId>
8484
<artifactId>logback-classic</artifactId>
8585
<version>${logback.version}</version>
86+
<scope>test</scope>
8687
</dependency>
8788

8889
<dependency>

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/App.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)