|
18 | 18 |
|
19 | 19 | import com.google.gson.Gson; |
20 | 20 | import com.google.gson.JsonObject; |
| 21 | +import com.microsoft.playwright.options.AriaRole; |
21 | 22 | import com.microsoft.playwright.options.Location; |
| 23 | +import com.microsoft.playwright.options.MouseButton; |
| 24 | + |
22 | 25 | import org.junit.jupiter.api.Assumptions; |
23 | 26 | import org.junit.jupiter.api.BeforeAll; |
24 | 27 | import org.junit.jupiter.api.Test; |
@@ -204,6 +207,68 @@ void traceGroupGroupEnd(@TempDir Path tempDir) throws Exception { |
204 | 207 | assertEquals(asList("outer group", "Page.navigate", "inner group 1", "Frame.click", "inner group 2", "Page.isVisible"), calls); |
205 | 208 | } |
206 | 209 |
|
| 210 | + @Test |
| 211 | + void shouldTraceVariousAPIs(@TempDir Path tempDir) throws Exception { |
| 212 | + context.tracing().start(new Tracing.StartOptions()); |
| 213 | + |
| 214 | + page.clock().install(); |
| 215 | + |
| 216 | + page.setContent("<input type='text' />"); |
| 217 | + page.locator("input").click(new Locator.ClickOptions().setButton(MouseButton.RIGHT)); |
| 218 | + page.getByRole(AriaRole.TEXTBOX).click(); |
| 219 | + page.keyboard().type("Hello world this is a very long string what happens when it overflows?"); |
| 220 | + page.keyboard().press("Control+c"); |
| 221 | + page.keyboard().down("Shift"); |
| 222 | + page.keyboard().insertText("Hello world"); |
| 223 | + page.keyboard().up("Shift"); |
| 224 | + page.mouse().move(0, 0); |
| 225 | + page.mouse().down(); |
| 226 | + page.mouse().move(100, 200); |
| 227 | + page.mouse().wheel(5, 7); |
| 228 | + page.mouse().up(); |
| 229 | + page.clock().fastForward(1000); |
| 230 | + page.clock().fastForward("30:00"); |
| 231 | + page.clock().pauseAt("2050-02-02"); |
| 232 | + page.clock().runFor(10); |
| 233 | + page.clock().setFixedTime("2050-02-02"); |
| 234 | + page.clock().setSystemTime("2050-02-02"); |
| 235 | + |
| 236 | + page.clock().resume(); |
| 237 | + |
| 238 | + page.locator("input").click(new Locator.ClickOptions().setButton(MouseButton.RIGHT)); |
| 239 | + |
| 240 | + Path traceFile1 = tempDir.resolve("trace1.zip"); |
| 241 | + context.tracing().stop(new Tracing.StopOptions().setPath(traceFile1)); |
| 242 | + |
| 243 | + List<TraceEvent> events = parseTraceEvents(traceFile1); |
| 244 | + List<String> calls = events.stream().filter(e -> e.apiName != null).map(e -> e.apiName) |
| 245 | + .collect(Collectors.toList()); |
| 246 | + assertEquals(asList( |
| 247 | + "Clock.install", |
| 248 | + "Page.setContent", |
| 249 | + "Frame.click", |
| 250 | + "Frame.click", |
| 251 | + "Keyboard.type", |
| 252 | + "Keyboard.press", |
| 253 | + "Keyboard.down", |
| 254 | + "Keyboard.insertText", |
| 255 | + "Keyboard.up", |
| 256 | + "Mouse.move", |
| 257 | + "Mouse.down", |
| 258 | + "Mouse.move", |
| 259 | + "Mouse.wheel", |
| 260 | + "Mouse.up", |
| 261 | + "Clock.fastForward", |
| 262 | + "Clock.fastForward", |
| 263 | + "Clock.pauseAt", |
| 264 | + "Clock.runFor", |
| 265 | + "Clock.setFixedTime", |
| 266 | + "Clock.setSystemTime", |
| 267 | + "Clock.resume", |
| 268 | + "Frame.click"), |
| 269 | + calls); |
| 270 | + } |
| 271 | + |
207 | 272 | private static class TraceEvent { |
208 | 273 | String type; |
209 | 274 | String name; |
|
0 commit comments