我有一个通过 postMessage 命令进行通信的网站
 window.parent.postMessage(communication, this.origin);
使用剧作家时,我正在尝试执行“消息”处理程序
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>)
控制台输出
Im here
setting return event MessageEvent
event was {}
我无法将我的期望放入代码中page.evaluate(),因为它是在它注入的 javascript 标签的上下文中执行的,而不是在规范的上下文中执行的。
我目前使用 global-setup.ts 文件通过 playwright 加载 url。
await page.goto('https://test1.com/');
我还在此处执行额外的代码并存储对象的状态(一切按预期工作)
我的 playwright.config.ts 文件引用了 globalsetup,这一切都按预期工作。
在我的配置文件中,我还设置了baseUrl,但是,我正在努力寻找将baseUrl传递到我的global-setup.ts文件而不是对其进行硬编码的方法。
谢谢!
我有一个必需的登录表单输入:
<input
  autoComplete="email"
  defaultValue={email}
  disabled={state === 'submitting'}
  id="email"
  name="email"
  placeholder={t('user-authentication:email-placeholder')}
  required // HERE!
  type="email"
/>
如何测试 Playwright 是否需要输入?我在 Chromium 中的本机浏览器警告是:“请填写此字段。”
有没有办法在剧作家中检查/断言此警告?或者另一种方法来测试是否需要输入?
我尝试在输入中不写入任何内容,.fill('')然后按 Enter 键page.keyboard.press('Enter'),但这些并没有导致出现警告。
如何在剧作家中无任何条件地给予固定(隐式等待)等待
就像我们在 cypress 中所做的那样:
等待(600);
谢谢
就像我们在 cypress 中所做的那样:
等待(600);
我正在编写剧作家测试并在我的本地计算机上测试它们,该计算机具有 SSL,但证书经常给出错误。
我想在本地计算机上进行开发时忽略所有与 HTTPS 相关的错误。(我将使用有效的证书在云中进行最终测试。)
对于浏览器,您可以像这样ignoreHTTPSErrors添加:contextOptions
const config: PlaywrightTestConfig = {
  projects: [
    {
      name: 'Safari MacBook Air',
      use: {
        browserName: 'webkit',
        viewport: {
          width: 2560,
          height: 1620,
        },
        contextOptions: {
          ignoreHTTPSErrors: true,
        },
      },
    },
但是,我找不到类似的选项devices:
{
  name: 'iPhone 6/7/8',
  use: devices['iPhone 8'],
},
如何忽略设备的 HTTPS 错误?
我正在开发这个模板,其中使用 DragTo() 函数进行拖放。当我在头部模式下运行测试时,它工作得很好。但是当我在无头模式下运行测试时,它根本不会拖动任何东西,并且测试将在页面空白的情况下通过。有什么方法可以减慢拖动速度,以便页面可以在跳转到其他操作之前识别拖动的元素?
我尝试通过以下方式添加超时但仍然没有运气:
await this.page.locator('text=Column').first()
  .dragTo(this.page.locator('[role="tabpanel"]')
  .first(), {force:true}), {timeout:3000};
朋友们,有没有人有代码可以让我将屏幕截图包含在我想要的行中,并将此打印附加到标准剧作家报告中?
我正在使用带有 javascript 的 playwright在此处输入图像描述 npx plawright show-report
我希望能够在所有测试中使用定位器变量,而不必每次在每个测试中都定义它。就像是:
// @ts-check
const { test, expect } = require('@playwright/test');
test.beforeEach( async ({ page }) => {
  await page.goto('[desired URL]');  
});
// I want to make this variable global to be able to use it within all the tests.
const signInBtn = page.getByTestId('some-button'); // how to resolve 'page' here??
test.describe('My set of tests', () => {
  test('My test 1', async ({ page }) => {
    await expect(page).toHaveTitle(/Some-Title/);
    await expect(signInBtn).toBeEnabled();     // I wanna use the variable here...
  });
  
  test('My test 2', …我正在进行端到端 UI 测试,当我尝试为 Harmony Web UI 组件 (<ext-support_he-select>) 选择一个选项时,playwright 无法识别 customere 标签,并且错误提示不是选择选项。
我也无法使用无头录音机记录下拉选择选项,如果有人遇到过此类问题,请告诉我。
HTML 选择代码: { <ext-support_he-select id="workspace-dropdown" class="basic-dropdown basic-workspace-dropdown 低于有效" aria-labelledby="workspace-label" role="combobox" current-value= “” aria-controls =“” aria-disabled =“假” aria-expanded =“假” aria-haspopup =“列表框” tabindex =“0”位置=“下方” aria-activedescendant =“选项14”>
    <ext-support_he-option selected="" value="" aria-selected="true" class="selected" role="option" id="option-14" aria-posinset="1" aria-setsize="9"> Select a Workspace </ext-support_he-option>
  
         
    <ext-support_he-option value="accountPlans" aria-selected="false" role="option" id="option-15" aria-posinset="2" aria-setsize="9"> Account Plans </ext-support_he-option>
   
    <ext-support_he-option value="accounts" aria-selected="false" role="option" id="option-16" aria-posinset="3" aria-setsize="9"> Accounts </ext-support_he-option>
   
    <ext-support_he-option value="contacts" aria-selected="false" role="option" id="option-17" aria-posinset="4" aria-setsize="9"> Contacts </ext-support_he-option> …playwright ×9
javascript ×2
automation ×1
cypress ×1
html ×1
html-input ×1
required ×1
testing ×1
typescript ×1
ui-testing ×1