我想验证文本中包含 one 或 two。
await expect(this.title).toHaveText('one').or('two')
在 Playwright 中能这样实现吗?
同样的写法也能用在句子内部吗,比如下面这样
await expect(this.title).toHaveText("this is "+('first').or('second')+ "sentence");
我想验证文本中包含 one 或 two。
await expect(this.title).toHaveText('one').or('two')
在 Playwright 中能这样实现吗?
同样的写法也能用在句子内部吗,比如下面这样
await expect(this.title).toHaveText("this is "+('first').or('second')+ "sentence");
I'd like to verify that the text contains either one or two:
await expect(this.title).toHaveText('one').or('two')
Can this be made to work in Playwright?
Could the same thing also appear within a sentence, for example
await expect(this.title).toHaveText("this is "+('first').or('second')+ "sentence");
可以用正则表达式提供期望的文本。
await expect(this.title).toHaveText(/^(one|two)$/);
由于 .toHaveText() 比较的是完整文本,不给正则表达式加锚点应该也行(我没有测试过,只是参考了 Locator.toHaveText() 的文档 (https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-text))。
await expect(this.title).toHaveText(/one|two/);
The expected text can be supplied as a regular expression:
await expect(this.title).toHaveText(/^(one|two)$/);
Since .toHaveText() compares against the complete text, leaving the regexp unanchored should work too (I haven't tested this, I'm only going by the Locator.toHaveText() documentation (https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-text)):
await expect(this.title).toHaveText(/one|two/);
Playwright v1.33 加入了 Locator.or (https://playwright.dev/docs/api/class-locator#locator-or),可以这样使用。
const leftTitle = page.getByRole('heading', { name: 'One' });
const rightTitle = page.getByRole('heading', { name: 'Two' });
await expect(leftTitle.or(rightTitle)).toBeVisible();
With Playwright v1.33 came Locator.or (https://playwright.dev/docs/api/class-locator#locator-or), which can be used this way:
const leftTitle = page.getByRole('heading', { name: 'One' });
const rightTitle = page.getByRole('heading', { name: 'Two' });
await expect(leftTitle.or(rightTitle)).toBeVisible();
我的尝试如下。 不过,看起来并不存在这条命令。 gdb 能实现这样的功能吗?
我的代码中有下面这个函数。 TsLint 对它报告了这个错误。 有人能解释一下这条消息的含义吗?
我在给游戏制作数字时钟,需要把当前时间(小时和分钟)显示成 HH:MM:SS 这样的格式。应该从哪里取得所需的时间值?