Skip to content
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

fix(recorder): Locator picker had wrong initial language in language bindings #27706

Merged
merged 3 commits into from
Oct 22, 2023

Conversation

mxschmitt
Copy link
Member

Description

When a language port was using Inspector with the "Locator Picker" feature, it only recognised JavaScript as a language by default. As a workaround the user was able to click record, interact with the page and then the language would be correctly used -> csharp e.g. would work in the "Locator Picker".

Why?

Our language bindings are setting PW_LANG_NAME=<sdkLanguage> env var -> good. Our recorder harness also uses this along its internal state here:

const language = params.language || context.attribution.playwright.options.sdkLanguage;

and it gets used here (no parameter means: we use the first language aka. primary language):

this._currentLanguage = this._contextRecorder.languageName();

The only issue is that the Inspector frontend in the beginning does not know which language it should use and pass over to the server side, it then falls back to JavaScript.

Proposed fix

Instead of passing it over from the frontend to the server side, we just always use it from the server side, aka. "currentLanguage". When the user switches languages in the frontend, "currentLanguage" already gets updated properly via the "fileChanged" event.

microsoft/playwright-dotnet#2718

@github-actions

This comment has been minimized.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance for a test?

Signed-off-by: Max Schmitt <max@schmitt.mx>
@mxschmitt mxschmitt merged commit 6d7d370 into microsoft:main Oct 22, 2023
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Test results for "tests 1"

9 flaky ⚠️ [chromium] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [chromium] › page/page-event-request.spec.ts:101:3 › should report navigation requests and responses handled by service worker
⚠️ [chromium] › page/page-event-request.spec.ts:130:3 › should report navigation requests and responses handled by service worker with routing
⚠️ [firefox] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [playwright-test] › ui-mode-test-ct.spec.ts:55:5 › should run component tests after editing test
⚠️ [chromium] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [webkit] › library/browsercontext-reuse.spec.ts:50:1 › should reset serviceworker
⚠️ [webkit] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [webkit] › page/page-wait-for-navigation.spec.ts:85:3 › should work with clicking on links which do not commit navigation

25926 passed, 603 skipped
✔️✔️✔️

Merge workflow run.

@PeterHevesi
Copy link

Nice, that worked :) But still not 100% correctly, if I do Locator("<some_xpath_selector1>").Locator("<some_xpath_selector2>")
then it doesn't work.

I had to put xpath= in front of it, so when having it like this, it works just fine, but shouldn't be required :)
Locator("xpath=<some_xpath_selector1>").Locator("xpath=<some_xpath_selector2>")

@mxschmitt
Copy link
Member Author

Nice, that worked :) But still not 100% correctly, if I do Locator("<some_xpath_selector1>").Locator("<some_xpath_selector2>") then it doesn't work.

I had to put xpath= in front of it, so when having it like this, it works just fine, but shouldn't be required :) Locator("xpath=<some_xpath_selector1>").Locator("xpath=<some_xpath_selector2>")

This gets addressed in #27742.

Germandrummer92 pushed a commit to OctoMind-dev/playwright that referenced this pull request Oct 27, 2023
…bindings (microsoft#27706)

**Description**

When a language port was using Inspector with the "Locator Picker"
feature, it only recognised JavaScript as a language by default. As a
workaround the user was able to click record, interact with the page and
then the language would be correctly used -> csharp e.g. would work in
the "Locator Picker".

**Why?**

Our language bindings are setting `PW_LANG_NAME=<sdkLanguage>` env var
-> good. Our recorder harness also uses this along its internal state
here:


https://github.com/microsoft/playwright/blob/b9b289b6415515b1b8e1a2524ed6425c8992af5a/packages/playwright-core/src/server/recorder.ts#L369

and it gets used here (no parameter means: we use the first language
aka. primary language):


https://github.com/microsoft/playwright/blob/b9b289b6415515b1b8e1a2524ed6425c8992af5a/packages/playwright-core/src/server/recorder.ts#L95

The only issue is that the Inspector frontend in the beginning does not
know which language it should use and pass over to the server side, it
then falls back to JavaScript.

**Proposed fix**

Instead of passing it over from the frontend to the server side, we just
always use it from the server side, aka. "currentLanguage". When the
user switches languages in the frontend, "currentLanguage" already gets
updated properly via the "fileChanged" event.

microsoft/playwright-dotnet#2718

---------

Signed-off-by: Max Schmitt <max@schmitt.mx>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants