-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathJavaApiRunner.java
49 lines (39 loc) · 1.36 KB
/
JavaApiRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package driver;
import com.intuit.karate.Http;
import com.intuit.karate.Json;
import com.intuit.karate.Match;
import com.intuit.karate.driver.Driver;
import com.intuit.karate.driver.chrome.Chrome;
import com.intuit.karate.http.HttpServer;
import java.util.Map;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
/**
*
* @author pthomas3
*/
class JavaApiRunner {
static HttpServer server;
static String serverUrl;
@BeforeAll
static void beforeAll() {
server = ServerStarter.start(0);
serverUrl = "http://localhost:" + server.getPort();
}
@Test
void testChromeHybrid() {
Driver driver = Driver.start("chrome");
driver.setUrl(serverUrl + "/05");
Map response = Http.to(serverUrl + "/api/05").get().json().asMap();
Match.that(response).isEqualTo("{ message: 'hello world' }");
driver.click("button");
driver.waitForText("#containerDiv", "hello world");
Chrome chrome = (Chrome) driver; // intercept() is only supported by chrome
Json json = Json.of("{ patterns: [{ urlPattern: '*/api/*' }] }");
json.set("mock", "src/test/java/driver/05_mock.feature");
chrome.intercept(json.asMap());
driver.click("button");
driver.waitForText("#containerDiv", "hello faked");
driver.quit();
}
}