Skip to content

within()/I.switchTo(): Context of a 2nd iframe is used though I switched to 1st iframe #3894

@mirao

Description

@mirao

It works as expected in 3.5.3 and doesn't work in 3.5.5, so it seems to be a regression in 3.5.5 (or maybe in 3.5.4)

What are you trying to achieve?

The test should fail, because no such text "The iframe element" is in the 1st iframe on the page (it's a Google ads iframe). Note the text "The iframe element" is in the 2nd iframe instead (in the element "h1").

This is an output from the test run in CodeceptJS 3.5.3 (expected output) ✔️ :

My --
 › [Session] Starting singleton browser session
  test something
    I am on page "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe"
    I click "#accept-choices"
    I wait 5
    I switch to {xpath: (.//iframe)[position()=1]}
    I see text equals "The iframe element", "h1"
 › <screenshotOnFail> Test failed, try to save a screenshot
 › Screenshot is saving to /home/mirao/workspace/codeceptjs/tests/my/output/test_something.failed.png
  ✖ FAILED in 6583ms


-- FAILURES:

  1) My
       test something:
     Element "h1" was not found by text|CSS|XPath
      at new ElementNotFound (/home/mirao/workspace/codeceptjs/node_modules/.pnpm/[email protected]_it6hatrurk4vupt6qhkwl6ubhy/node_modules/codeceptjs/lib/helper/errors/ElementNotFound.js:14:11)
      at assertElementExists (/home/mirao/workspace/codeceptjs/node_modules/.pnpm/[email protected]_it6hatrurk4vupt6qhkwl6ubhy/node_modules/codeceptjs/lib/helper/Playwright.js:3291:11)
      at Playwright.proceedSee (/home/mirao/workspace/codeceptjs/node_modules/.pnpm/[email protected]_it6hatrurk4vupt6qhkwl6ubhy/node_modules/codeceptjs/lib/helper/Playwright.js:3128:5)
  
  Scenario Steps:
  - I.seeTextEquals("The iframe element", "h1") at Test.<anonymous> (./My_test.ts:10:7)
  - I.switchTo({xpath: (.//iframe)[position()=1]}) at Test.<anonymous> (./My_test.ts:9:7)
  - I.wait(5) at Test.<anonymous> (./My_test.ts:8:7)
  - I.click("#accept-choices") at Test.<anonymous> (./My_test.ts:7:7)
  - I.amOnPage("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe") at Test.<anonymous> (./My_test.ts:4:7)
  
  Artifacts:
  - screenshot: /home/mirao/workspace/codeceptjs/tests/my/output/test_something.failed.png


  FAIL  | 0 passed, 1 failed   // 7s
Run with --verbose flag to see complete NodeJS stacktrace

What do you get instead?

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

The test in 3.5.5 passes 🐞 :

My --
 › [Session] Starting singleton browser session
  test something
    I am on page "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe"
    I click "#accept-choices"
    I wait 5
    I switch to {xpath: (.//iframe)[position()=1]}
    I see text equals "The iframe element", "h1"
  ✔ OK in 6426ms

I tried it also with the fix #3892, but I'm getting the same result.

Provide test source code if related

Feature("My");

Scenario("test something", ({ I }) => {
    I.amOnPage(
        "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe"
    );
    I.click("#accept-choices");
    I.wait(5); // Wait for Google ads to be loaded
    I.switchTo(locate("iframe").at(1)); // Switch to the iframe with Google ads
    I.seeTextEquals("The iframe element", "h1");
});

Details

  • CodeceptJS version: 3.5.5
  • NodeJS Version: 18.15
  • Operating System: Ubuntu 22.04
  • Playwright 1.37.1
  • Configuration file:
export const config: CodeceptJS.MainConfig = {
    tests: "./*_test.ts",
    output: "./output",
    helpers: {
        Playwright: {
            browser: "chromium",
            url: "http://localhost",
            show: true,
        },
    },
    name: "my",
};

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