Skip to content

Commit d2e4f93

Browse files
committed
Initial client implementation
1 parent 8597346 commit d2e4f93

23 files changed

+1105
-60
lines changed

cdtp-java-client/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
MVN=mvn
3+
4+
SONAR_HOST=http://localhost:9999
5+
6+
sonar-analysis:
7+
# Running sonar analysis
8+
$(MVN) clean test && $(MVN) sonar:sonar -Dsonar.host.url=$(SONAR_HOST) \
9+
-Dsonar.tests="src/test" \
10+
-Dsonar.exclusions="**/com/github/kklisura/cdtp/protocol/**/*" \
11+
-Dsonar.coverage.exclusions="**/com/github/kklisura/cdtp/protocol/**/*"

cdtp-java-client/pom.xml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
<jacoco.version>0.8.0</jacoco.version>
2525
<easy.mock.version>3.4</easy.mock.version>
2626
<jsonassert.version>1.5.0</jsonassert.version>
27-
<tyrus.server.version>1.13.1</tyrus.server.version>
28-
<tyrus.server.version>1.13.1</tyrus.server.version>
29-
<tyrus.container.version>1.2.1</tyrus.container.version>
3027
<mockwebserver.version>2.7.5</mockwebserver.version>
3128
</properties>
3229

@@ -36,10 +33,14 @@
3633
<artifactId>javax.websocket-api</artifactId>
3734
<version>${websocket.api.version}</version>
3835
</dependency>
39-
4036
<dependency>
4137
<groupId>org.glassfish.tyrus</groupId>
42-
<artifactId>tyrus-container-jdk-client</artifactId>
38+
<artifactId>tyrus-client</artifactId>
39+
<version>${tyrus.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.glassfish.tyrus</groupId>
43+
<artifactId>tyrus-container-grizzly-server</artifactId>
4344
<version>${tyrus.version}</version>
4445
</dependency>
4546

@@ -83,28 +84,10 @@
8384
<version>${easy.mock.version}</version>
8485
<scope>test</scope>
8586
</dependency>
86-
<dependency>
87-
<groupId>org.jacoco</groupId>
88-
<artifactId>jacoco-maven-plugin</artifactId>
89-
<version>${jacoco.version}</version>
90-
<scope>test</scope>
91-
</dependency>
9287
<dependency>
9388
<groupId>org.glassfish.tyrus</groupId>
9489
<artifactId>tyrus-server</artifactId>
95-
<version>${tyrus.server.version}</version>
96-
<scope>test</scope>
97-
</dependency>
98-
<dependency>
99-
<groupId>org.glassfish.tyrus</groupId>
100-
<artifactId>tyrus-container-grizzly-server</artifactId>
101-
<version>${tyrus.server.version}</version>
102-
<scope>test</scope>
103-
</dependency>
104-
<dependency>
105-
<groupId>org.glassfish.tyrus</groupId>
106-
<artifactId>tyrus-spi</artifactId>
107-
<version>${tyrus.server.version}</version>
90+
<version>${tyrus.version}</version>
10891
<scope>test</scope>
10992
</dependency>
11093
<dependency>
@@ -126,6 +109,7 @@
126109
<plugin>
127110
<groupId>org.jacoco</groupId>
128111
<artifactId>jacoco-maven-plugin</artifactId>
112+
<version>${jacoco.version}</version>
129113
<executions>
130114
<execution>
131115
<id>pre-unit-test</id>
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package com.github.kklisura.cdtp;
22

3+
import com.github.kklisura.cdtp.protocol.ChromeDevTools;
4+
import com.github.kklisura.cdtp.services.ChromeService;
5+
import com.github.kklisura.cdtp.services.exceptions.ChromeServiceException;
6+
import com.github.kklisura.cdtp.services.impl.ChromeServiceImpl;
7+
import com.github.kklisura.cdtp.services.model.chrome.ChromeTab;
8+
39
/**
410
* Hello world!
511
*
612
*/
713
public class App {
8-
public static void main( String[] args ) {
14+
public static void main( String[] args ) throws ChromeServiceException, InterruptedException {
15+
final ChromeService chromeService = new ChromeServiceImpl(9222);
16+
final ChromeTab tab = chromeService.createTab();
17+
18+
final ChromeDevTools devTools = chromeService.getDevTools(tab);
19+
20+
// Network requestWillBeSent event
21+
// Page loadEventFired
22+
23+
devTools.getPage().navigate("http://google.com");
924
}
1025
}

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/client/services/ChromeService.java renamed to cdtp-java-client/src/main/java/com/github/kklisura/cdtp/services/ChromeService.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package com.github.kklisura.cdtp.client.services;
1+
package com.github.kklisura.cdtp.services;
22

3-
import com.github.kklisura.cdtp.client.services.exceptions.ChromeServiceException;
4-
import com.github.kklisura.cdtp.client.services.model.chrome.ChromeTab;
5-
import com.github.kklisura.cdtp.client.services.model.chrome.ChromeVersion;
3+
import com.github.kklisura.cdtp.protocol.ChromeDevTools;
4+
import com.github.kklisura.cdtp.services.exceptions.ChromeServiceException;
5+
import com.github.kklisura.cdtp.services.model.chrome.ChromeTab;
6+
import com.github.kklisura.cdtp.services.model.chrome.ChromeVersion;
67

78
import java.util.List;
89

@@ -20,6 +21,14 @@ public interface ChromeService {
2021
*/
2122
List<ChromeTab> getTabs() throws ChromeServiceException;
2223

24+
/**
25+
* Creates a new chrome tab that points to about:blank
26+
*
27+
* @return Chrome tab.
28+
* @throws ChromeServiceException If creation fails for any reason.
29+
*/
30+
ChromeTab createTab() throws ChromeServiceException;
31+
2332
/**
2433
* Creates a new chrome tab.
2534
*
@@ -52,4 +61,12 @@ public interface ChromeService {
5261
* @throws ChromeServiceException If request fails for any reason.
5362
*/
5463
ChromeVersion getVersion() throws ChromeServiceException;;
64+
65+
/**
66+
* Gets the dev tools session to specified tab.
67+
*
68+
* @param tab Tab.
69+
* @return Dev tools.
70+
*/
71+
ChromeDevTools getDevTools(ChromeTab tab) throws ChromeServiceException;
5572
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.kklisura.cdtp.services;
2+
3+
import com.github.kklisura.cdtp.services.exceptions.ChromeDevToolsException;
4+
import com.github.kklisura.cdtp.services.model.chrome.MethodInvocation;
5+
6+
/**
7+
* Created by Kenan Klisura on 20/01/2018.
8+
*
9+
* @author Kenan Klisura
10+
*/
11+
public interface DevToolsService {
12+
/**
13+
* Invokes a dev tools method.
14+
*
15+
* @param returnProperty Return property.
16+
* @param clazz Return class type.
17+
* @param methodInvocation Method invocation definition.
18+
* @param <T> Type of a return class.
19+
* @return Return object.
20+
*/
21+
<T> T invoke(String returnProperty, Class<T> clazz, MethodInvocation methodInvocation) throws ChromeDevToolsException;
22+
}

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/client/services/WebSocketService.java renamed to cdtp-java-client/src/main/java/com/github/kklisura/cdtp/services/WebSocketService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.github.kklisura.cdtp.client.services;
1+
package com.github.kklisura.cdtp.services;
22

3-
import com.github.kklisura.cdtp.client.services.exceptions.WebSocketServiceException;
3+
import com.github.kklisura.cdtp.services.exceptions.WebSocketServiceException;
44

55
import java.net.URI;
66
import java.util.function.Consumer;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.kklisura.cdtp.services.exceptions;
2+
3+
/**
4+
* Chrome dev tools exception. Info consists of code and a message.
5+
*
6+
* @author Kenan Klisura
7+
*/
8+
public class ChromeDevToolsException extends Exception {
9+
private Long code = -1L;
10+
11+
/**
12+
* Instantiates a new Chrome dev tools exception.
13+
*
14+
* @param code Error code.
15+
* @param message Error message.
16+
*/
17+
public ChromeDevToolsException(Long code, String message) {
18+
super(message);
19+
this.code = code;
20+
}
21+
22+
/**
23+
* Instantiates a new Chrome dev tools exception.
24+
*
25+
* @param message Error message.
26+
* @param cause Exception cause.
27+
*/
28+
public ChromeDevToolsException(String message, Throwable cause) {
29+
super(message, cause);
30+
}
31+
32+
/**
33+
* Gets the error code.
34+
*
35+
* @return Error code.
36+
*/
37+
public Long getCode() {
38+
return code;
39+
}
40+
}

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/client/services/exceptions/ChromeServiceException.java renamed to cdtp-java-client/src/main/java/com/github/kklisura/cdtp/services/exceptions/ChromeServiceException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.kklisura.cdtp.client.services.exceptions;
1+
package com.github.kklisura.cdtp.services.exceptions;
22

33
/**
44
* Chrome service exception.

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/client/services/exceptions/WebSocketServiceException.java renamed to cdtp-java-client/src/main/java/com/github/kklisura/cdtp/services/exceptions/WebSocketServiceException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.kklisura.cdtp.client.services.exceptions;
1+
package com.github.kklisura.cdtp.services.exceptions;
22

33
/**
44
* Web socket service exception.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.kklisura.cdtp.services.factory;
2+
3+
import com.github.kklisura.cdtp.services.WebSocketService;
4+
import com.github.kklisura.cdtp.services.exceptions.WebSocketServiceException;
5+
6+
/**
7+
* Web service socket factory.
8+
*
9+
* @author Kenan Klisura
10+
*/
11+
@FunctionalInterface
12+
public interface WebSocketServiceFactory {
13+
/**
14+
* Creates a web socket service given a web socket url.
15+
*
16+
* @param wsUrl Web socket url.
17+
* @return Web socket service.
18+
*/
19+
WebSocketService createWebSocketService(String wsUrl) throws WebSocketServiceException;
20+
}

0 commit comments

Comments
 (0)