-
Notifications
You must be signed in to change notification settings - Fork 296
fix(tracing): send addStackToTracingNoReply on the LocalUtils connection #1967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+93
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
playwright/src/test/java/com/microsoft/playwright/TestTracingOverConnect.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * | ||
| * Licensed 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 com.microsoft.playwright; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static com.microsoft.playwright.TestBrowserTypeConnect.launchBrowserServer; | ||
| import static com.microsoft.playwright.Utils.mapOf; | ||
| import static com.microsoft.playwright.Utils.parseZip; | ||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class TestTracingOverConnect extends TestBase { | ||
| private static final String SRC_DIRS = System.getenv("PLAYWRIGHT_JAVA_SRC") == null ? "src/test/java" : System.getenv("PLAYWRIGHT_JAVA_SRC"); | ||
|
|
||
| private TestBrowserTypeConnect.BrowserServer browserServer; | ||
|
|
||
| @Override | ||
| Playwright.CreateOptions playwrightOptions() { | ||
| // Set the source root here rather than relying on the environment so that the test runs in the | ||
| // regular test job too, not only in the one that passes PLAYWRIGHT_JAVA_SRC. | ||
| return new Playwright.CreateOptions().setEnv(mapOf("PLAYWRIGHT_JAVA_SRC", SRC_DIRS)); | ||
| } | ||
|
|
||
| @Override | ||
| @BeforeAll | ||
| void launchBrowser() { | ||
| initBrowserType(); | ||
| browserServer = launchBrowserServer(browserType); | ||
| browser = browserType.connect(browserServer.wsEndpoint); | ||
| } | ||
|
|
||
| @Override | ||
| @AfterAll | ||
| void closeBrowser() { | ||
| super.closeBrowser(); | ||
| if (browserServer != null) { | ||
| browserServer.process.destroyForcibly(); | ||
| browserServer = null; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void shouldRecordSourcesForBrowserFromConnect(@TempDir Path tmpDir) throws IOException { | ||
| context.tracing().start(new Tracing.StartOptions().setSources(true)); | ||
| page.navigate(server.EMPTY_PAGE); | ||
| page.setContent("<button>Click</button>"); | ||
| page.click("'Click'"); | ||
| Path trace = tmpDir.resolve("trace1.zip"); | ||
| context.tracing().stop(new Tracing.StopOptions().setPath(trace)); | ||
|
|
||
| Map<String, byte[]> entries = parseZip(trace); | ||
| Map<String, byte[]> sources = entries.entrySet().stream().filter(e -> e.getKey().startsWith("src/")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| assertEquals(1, sources.size()); | ||
|
|
||
| String path = getClass().getName().replace('.', File.separatorChar); | ||
| String[] srcRoots = SRC_DIRS.split(File.pathSeparator); | ||
| // Resolve in the last specified source dir. | ||
| Path sourceFile = Paths.get(srcRoots[srcRoots.length - 1], path + ".java"); | ||
| byte[] thisFile = Files.readAllBytes(sourceFile); | ||
| assertEquals(new String(thisFile, UTF_8), new String(sources.values().iterator().next(), UTF_8)); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.