*更新
22.6.2022/在另一个使用OAuth的站点上重现了这个问题,当globalSetup应该在OAuth域上执行操作时,它失败了
21.6.2022/跟踪。zip显示OAuth登录的url是正确的,但屏幕截图显示的是一个空白的白色页面
我努力实现的目标:
我试图在我的剧作家TypeScript测试项目中使用缓存身份验证。以下是他们的文件-https://playwright.dev/docs/test-auth.
这样,在运行每个测试之前,登录 全局设置。输电系统 完成一次,然后缓存以备将来测试。
问题:
测试失败,返回页面。点击:超时30000ms。
当我使用 $env:PWDEBUG=1 没有问题。如果我使用 0,问题出现。
快速工作流:
域abc中的主登录页。通用域名格式
点击;通过电子邮件登录;
它使用电子邮件登录表单(“占位符=”电子邮件地址“)进入另一个域此处存在)
我注意到:
我拍摄了屏幕截图和日志,当DEBUG=0时,它似乎永远不会转到“缺失”元素所在的页面。在工作流#1中,单击按钮;使用电子邮件登录;,但是由于某种原因,电子邮件登录表单页面不可见。我试着增加更多的超时,更多的等待加载等,但没有任何效果。注意:如果重要的话,单击后的登录页面会转到另一个域进行登录。但DEBUG何时为1并不重要。。
如果我只使用beforeach,一切都很好,但这并不是剧作家在他们的文档中指示的。
npx playwright test
Running 3 tests using 1 worker
page.click: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "[placeholder="Email Address"]"
============================================================
at ..全局设置。输电系统:19
18 | // Click [placeholder="Email Address"]
> 19 | await page.click('[placeholder="Email Address"]');
import { chromium, FullConfig } from '@playwright/test';
async function globalSetup(config: FullConfig) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://website.myapp.fi/app/');
// Have tried this without waitForNavigation with no difference in output
await Promise.all([
page.waitForNavigation(),
page.locator('div[role="button"]:has-text("email")').click(),
]);
// Click [placeholder="Email Address"]
await page.click('[placeholder="Email Address"]');
await page.locator('[placeholder="Email Address"]').fill('email..');
// Click [placeholder="Password"]
await page.click('[placeholder="Password"]');
await page.locator('[placeholder="Password"]').fill('password..');
// Click button:has-text("Sign in")
await page.click('button:has-text("Sign in")');
// Select company
await page.click('.b-number-cell');
await page.waitForLoadState('networkidle');
// Save signed-in state to 'storageState.json'.
await page.context().storageState({ path: 'storageState.json'
await browser.close();
}
export default globalSetup;
编辑:添加剧作家。配置。输电系统
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
const config: PlaywrightTestConfig = {
globalSetup: require.resolve('./global-setup'),
testDir: './tests',
timeout: 30 * 1000,
expect: {
timeout: 5000
},
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
actionTimeout: 0,
trace: 'on-first-retry',
// Tell all tests to load signed-in state from 'storageState.json'.
storageState: 'storageState.json'
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},
],
};
export default config;

未知地区 1F
从提供的详细信息来看,您似乎提供了30秒的超时时间。很明显 调试 模式测试不需要遵守这一点。作为第一步,你能试着增加这个吗
超时:60*1000,
也因为错误是特定于特定操作的-
等待选择器“;[占位符=“电子邮件地址”]&引用;
您还应该为该特定操作设置超时-
await page.click(‘[placeholder="Email Address"]’, { timeout: 60000 });