带有剧作家的测试元标记
我想在《剧作家》中测试Web应用程序的元标记,但是我在官方文档中没有找到任何信息。有人可以通过元数据测试向我建议吗?
例如,我试图测试: < meta name =“描述” content =“ sosity”>
test("Meta data", async ({ page }) => {
await page.goto(env.baseUrl)
const metaDescription = page.locator('meta [name="description"]')
await expect(metaDescription).toHaveText("something")
})
,结果是:
- 接收的字符串是“”
- 等待选择器'meta [name =“ description”]''
是什么问题如何以正确的方式测试它?
I want to test meta tags of the web application in Playwright, but I haven't found any info in the official documentation. Can somebody advise me with meta data testing?
For example, I have tried to test:<meta name="description" content="something">
test("Meta data", async ({ page }) => {
await page.goto(env.baseUrl)
const metaDescription = page.locator('meta [name="description"]')
await expect(metaDescription).toHaveText("something")
})
and the result is:
- The received string is ""
- waiting for selector 'meta [name="description"]'
What is wrong and how to test it in the right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的定位器选择器什么都不匹配。
meta [name =“ description”]
目标元素meta
带有属性的元素name =“ description”
。要定位元元素本身,您必须使用meta [name =“ description”]
(请注意删除的空间)。此外,元元素将文本保存在
content
属性中。这就是为什么tohaveText
无法正常工作的原因。尝试tohaveatTribute
。这是固定版本:
Your locator selector is matching nothing.
meta [name="description"]
targets elements inside ameta
element with the attributename="description"
. To target the meta element itself you have to usemeta[name="description"]
(note the removed space).Additionally, the meta element holds the text in the
content
attribute. That's whytoHaveText
can't work. TrytoHaveAttribute
instead.Here's the fixed version: