javascript - How to button clicked using playwright testing framework? - Stack Overflow

Currently , i am doing an end to end testing in my nuxt project. I want to test the frontend of my proj

Currently , i am doing an end to end testing in my nuxt project. I want to test the frontend of my project to ensure the UI is presentable and clickable. However , I am facing a problem for my button. It felt like button is not clicked. I am pretty sure the css selector for my button is correctly defined as shown in here

The screenshot shows that the button is hovered over or partially clicked. Is there any way to solve this issue ?

page.spec.ts

import { resolve, join } from 'path'
import { test, expect } from '@playwright/test'

const ROOT_PATH = resolve(__dirname, '..', 'screenshots')

test('job board test', async ({ page, baseURL }) => {
  await page.goto(baseURL + '/') // <-- Nuxt app is running and route '/' is showing.
  const html = await page.innerHTML('body')
  console.log(html)
  await expect(page.locator('h2').locator('text= meow')).toBeVisible()
  await page.fill('text=User name', 'jeff');
  await page.fill('text= Password', 'jeff');

  await page.locator('.v-btn').click(); // button clicked

  // Step 1 - Is Homepage working
  await page.screenshot({ path: join(ROOT_PATH, 'detail.png') })

})

Currently , i am doing an end to end testing in my nuxt project. I want to test the frontend of my project to ensure the UI is presentable and clickable. However , I am facing a problem for my button. It felt like button is not clicked. I am pretty sure the css selector for my button is correctly defined as shown in here

The screenshot shows that the button is hovered over or partially clicked. Is there any way to solve this issue ?

page.spec.ts

import { resolve, join } from 'path'
import { test, expect } from '@playwright/test'

const ROOT_PATH = resolve(__dirname, '..', 'screenshots')

test('job board test', async ({ page, baseURL }) => {
  await page.goto(baseURL + '/') // <-- Nuxt app is running and route '/' is showing.
  const html = await page.innerHTML('body')
  console.log(html)
  await expect(page.locator('h2').locator('text= meow')).toBeVisible()
  await page.fill('text=User name', 'jeff');
  await page.fill('text= Password', 'jeff');

  await page.locator('.v-btn').click(); // button clicked

  // Step 1 - Is Homepage working
  await page.screenshot({ path: join(ROOT_PATH, 'detail.png') })

})
Share Improve this question edited Jun 22, 2022 at 2:18 kissu 47k16 gold badges90 silver badges189 bronze badges asked Jun 22, 2022 at 1:28 Gavin Teo JuenGavin Teo Juen 3202 gold badges8 silver badges20 bronze badges 1
  • There is no error it seems so it would be hard for anyone to help you out. would you mind try using trace and view or provide the trace ? You can enable it in your global config as details provided here - playwright.dev/docs/trace-viewer#recording-a-trace Keep it on instead of on-first-retry – Amol Chavan Commented Jun 22, 2022 at 3:46
Add a ment  | 

1 Answer 1

Reset to default 4

You can try force clicking the button. Setting force to true will bypass the actionability check.

 await page.locator('.v-btn').click({force: true});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745347275a4623613.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信