Skip to content

Unable to move cursor when multiple elements exist: locator.boundingBox: Error: strict mode violation #3879

@mirao

Description

@mirao

It's a regression in 3.5.4 (also 3.5.5 is affected). CC: @kobenguyent

What are you trying to achieve?

The test should pass (a first found element should be used).
This is how it behaves in 3.5.3

  Test
    I am on page "https://codecept.io/"
    I move cursor to {xpath: .//div[@class = 'content']}
  ✔ OK in 2174ms

What do you get instead?

Provide console output if related. Use --verbose mode for more details.

-- FAILURES:

  1) My
       Test:
     locator.boundingBox: Error: strict mode violation: locator('xpath=.//div[@class = \'content\']') resolved to 3 elements:
    1) <div class="content" data-v-e3b729f8="">…</div> aka getByText('CodeceptJS is opensource MIT licensed testing framework. Works with your favorit')
    2) <div class="content" data-v-e3b729f8="">…</div> aka locator('#app div').filter({ hasText: 'Scenario Driven Write acceptance tests from user\'s perspective. Make tests reada' }).nth(1)
    3) <div class="content" data-v-e3b729f8=""></div> aka locator('div').filter({ hasText: '# Realworld Example Can we use it for long scenarios? Sure! const { faker } = re' }).nth(2)

=========================== logs ===========================
waiting for locator('xpath=.//div[@class = \'content\']')
============================================================
  locator.boundingBox: Error: strict mode violation: locator('xpath=.//div[@class = \'content\']') resolved to 3 elements:
      1) <div class="content" data-v-e3b729f8="">…</div> aka getByText('CodeceptJS is opensource MIT licensed testing framework. Works with your favorit')
      2) <div class="content" data-v-e3b729f8="">…</div> aka locator('#app div').filter({ hasText: 'Scenario Driven Write acceptance tests from user\'s perspective. Make tests reada' }).nth(1)
  
  Scenario Steps:
  - I.moveCursorTo({xpath: .//div[@class = 'content']}) at Test.<anonymous> (./My_test.ts:7:7)
  - I.amOnPage("https://codecept.io/") at Test.<anonymous> (./My_test.ts:6:7)

Provide test source code if related

Feature("My");

const { I } = inject();

Scenario("Test", () => {
    I.amOnPage("https://codecept.io/");
    I.moveCursorTo(locate("div").withAttr({ class: "content" }));
});

Details

  • CodeceptJS version: 3.5.4, 3.5.5
  • NodeJS Version: 18.15
  • Operating System: Ubuntu 22.04
  • Playwright 1.37.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions