我是 Playwright 的新手,由于某种原因我无法让它获取我的配置文件。
问题如下:
const browserChromium = await chromium.launch({ headless: false });) 中将 headless 设置为 false,则浏览器不会无头运行。我猜测所有这些问题都与我的配置文件没有被正确拾取有关(因为浏览器是无头运行的,即使无头设置为 false。)
我通过 WSL2 使用 Ubuntu 20.04。剧作家1.12.2
运行测试的命令:
npx playwright test test.ts
Run Code Online (Sandbox Code Playgroud)
这显示我正在运行正确的配置文件:
Using config at /myapp/tests/playwright/playwright.config.ts
以防万一,我还尝试手动指定配置文件:
npx playwright test test.ts --config=playwright.config.ts
Run Code Online (Sandbox Code Playgroud)
不过,在这两种情况下,即使配置文件中的 headless 为 false,浏览器也会以 headless 方式运行。
playwright.config.ts:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
headless: false,
// Artifacts
screenshot: 'on',
video: 'on',
},
};
export …Run Code Online (Sandbox Code Playgroud) 我是 Playwright 的新手,我试图获取选定的选项值,并将其更改为使用 playwright 包含 mat-select 元素的 mat-form-field 的另一个选项。
我试过
await page.selectOption('select#colors', { label: 'Blue' });
即 selectOptions 不适用于垫选择元素
<mat-form-field>
<mat-select id="selectColor" [formControl]="colcorselect" (click)="$event.stopPropagation()">
<mat-option *ngFor="let filter of savedColorOptions" [value]="filter (click)="savedFilterChange($event, filter)">
{{filter}}
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud) root@f083f367b874:/app# vim test.py
root@f083f367b874:/app# python test.py
Traceback (most recent call last):
File "test.py", line 13, in <module>
run(playwright)
File "test.py", line 3, in run
browser = playwright.chromium.launch(headless=False)
File "/usr/local/lib/python3.7/site-packages/playwright/sync_api/_generated.py", line 9449, in launch
firefoxUserPrefs=mapping.to_impl(firefox_user_prefs),
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_sync_base.py", line 103, in _sync
return task.result()
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_browser_type.py", line 90, in launch
raise e
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_browser_type.py", line 86, in launch
return from_channel(await self._channel.send("launch", params))
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_connection.py", line 36, in send
return await self.inner_send(method, params, False)
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_connection.py", line 54, in inner_send
result = …Run Code Online (Sandbox Code Playgroud) 我使用 Playwright dotnet 构建了一个工具,它在本地运行得很好。我正在尝试将其部署在我的 Windows 服务器上,以便其他人可以使用它,问题是如何在服务器上正确安装无头浏览器。
如果我在服务器上的 Windows PowerShell 中执行https://playwright.dev/dotnet/docs/intro上的所有快速启动任务,则在执行该playwright install步骤之前一切都会正常进行。此时我收到以下错误:
未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集“System.Runtime,版本= 5.0.0.0 ...
即使我尝试输入命令,dotnet add package System.Runtime它也会添加包,但是当我playwright install再次尝试时,它会抛出相同的错误。
我什至尝试部署该应用程序,当我到达需要 Playwright 的部分时,它说:
Looks like Playwright Test or Playwright was just installed or updated.Please run the following command to download new browsers:
npx playwright install
(PS,验证器坚持上述错误是代码并且不会让我提交,除非这是这样格式化,这是愚蠢的)
所以我说搞砸了,在服务器上安装了 Node,然后运行 npx 命令,它说它安装了浏览器,但我仍然收到相同的错误,告诉我运行 npx 命令。
有没有人有幸在 Windows 服务器上安装并实施了 Playwright?
我有一个通过 postMessage 命令进行通信的网站
window.parent.postMessage(communication, this.origin);
Run Code Online (Sandbox Code Playgroud)
使用剧作家时,我正在尝试执行“消息”处理程序
function eventListener(returnEvent: any): any {
window.addEventListener('message', function(event: MessageEvent) {
console.log('Im here');
if (event.data.messageId === 'payment-method') {
console.log('setting return event', event);
returnEvent = event;
return returnEvent;
}
});
}
...
let returnEvent: any = {};
await page.evaluate(eventListener, returnEvent);
await creditCardDetailsPage.fillFormValid();
await page.waitForTimeout(5000); //give time for message event to fire
console.log('event was', returnEvent);
await expect(returnEvent).toEqual(<MY DATA OBJECT HERE>)
Run Code Online (Sandbox Code Playgroud)
控制台输出
Im here
setting return event MessageEvent
event was {}
Run Code Online (Sandbox Code Playgroud)
我无法将我的期望放入代码中page.evaluate(),因为它是在它注入的 javascript 标签的上下文中执行的,而不是在规范的上下文中执行的。
我们使用puppeteer,有时还使用playwright来运行一些集成测试。我们模拟了一些目标页面的脚本依赖项,这会导致子资源完整性哈希不匹配。
无法使用计算的 SHA 在资源“http://localhost:3000/static/third-party/adobe-target/at-js/2.4.0-cname/at.js”的“integrity”属性中找到有效摘要-256 完整性'47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='。资源已被封锁。”
有没有办法通过标志或配置属性禁用完整性哈希检查?
google-chrome chromium subresource-integrity puppeteer playwright
我正在尝试使用 playwright 创建 .net 5.0 docker 映像。\n这是我的 DockerFile:
\nFROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base\nWORKDIR /app\n\nFROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build\nWORKDIR /src\nCOPY ["Agent.csproj", "Agent/"]\nRUN dotnet restore "Agent/Agent.csproj"\nCOPY . "/src/Agent"\nWORKDIR "/src/Agent"\nRUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano\nRUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -yq nodejs build-essential\nRUN npm install -g npm\n\nRUN dotnet add package Microsoft.Playwright\nRUN dotnet build "Agent.csproj" -c Release -o /app/build\nRUN npx playwright install\nRun Code Online (Sandbox Code Playgroud)\n但是一旦我在图像命令中运行dotnet run Agent就会出现以下错误:
Executable doesn't exist …Run Code Online (Sandbox Code Playgroud) 正如问题中预期的那样,我想知道是否可以尝试在按钮上执行单击操作,但如果它不在页面中,则测试会跳过该操作(不会卡住或引发错误)并继续执行下一个。更具体地说,我有一个模式,可以在其中向表中添加行,但我想做的是仅当模式中的给定按钮不存在时才添加新行,而如果存在则添加新行将首先按该按钮,然后继续添加新行。
我问你是否可以,因为我想在测试过程中避免使用条件语句。请告诉我,提前谢谢你:)
我尝试playwright从以下位置运行测试,但它显示消息npm install -D @playwright/test并且无法运行测试。我已经安装playwright为开发依赖项。有人可以告诉我这里有什么问题吗?
我尝试过以下运行:
1)
Test User@TestUser MINGW64 /c/Test
$ npx playwright test --headed
Please install @playwright/test package to use Playwright Test.
npm install -D @playwright/test
Run Code Online (Sandbox Code Playgroud)
测试用户@TestUser MINGW64 /c/Test $ npx playwright test 请安装@playwright/test 包以使用Playwright Test。npm install -D @playwright/test
// 测试/test1.spec.js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('https://playwright.dev/');
const title = page.locator('.navbar__inner .navbar__title');
await expect(title).toHaveText('Playwright');
});
Run Code Online (Sandbox Code Playgroud)
//包.json
{
"name": "play",
"version": "1.0.0",
"description": …Run Code Online (Sandbox Code Playgroud) 我有一些用 MS Test 2 框架编写的 UI 测试。
\n当我从 Visual Studio 2022 的测试资源管理器运行测试时,测试运行良好。
\n当我尝试调试测试时,我得到:
\nMicrosoft.Playwright.PlaywrightException: Connection closed (System.Threading.ThreadAbortException: System error.\n at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\n at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n at System.IO.Strategies.BufferedFileStreamStrategy.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)\n at System.IO.FileStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)\n at Microsoft.Playwright.Transport.StdIOTransport.SendAsync(String message))\n\n Stack Trace:\xe2\x80\x89\nConnection.SendMessageToServerAsync[T](String guid, String method, Object args)\nFrame.WaitForFunctionAsync(String expression, Object arg, FrameWaitForFunctionOptions options)\nMyTest.MyAsyncMethod()\xe2\x80\x89line\xe2\x80\x8923\nThreadOperations.ExecuteWithAbortSafety(Action action)\nRun Code Online (Sandbox Code Playgroud)\n在以下对 WaitForFunctionAsync 的调用中:
\nMicrosoft.Playwright.PlaywrightException: Connection closed (System.Threading.ThreadAbortException: System error.\n at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\n …Run Code Online (Sandbox Code Playgroud) playwright ×10
.net ×3
javascript ×3
testing ×2
typescript ×2
.net-6.0 ×1
c# ×1
chromium ×1
docker ×1
dockerfile ×1
npm ×1
puppeteer ×1
selector ×1