Skip to content

Playwright helper does not respect the device emulation setting when it opens a new session #4109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tsuemura opened this issue Jan 7, 2024 · 1 comment · Fixed by #4111

Comments

@tsuemura
Copy link
Contributor

tsuemura commented Jan 7, 2024

What are you trying to achieve?

If I open a new session during the session, Playwright does not respect the device emulation setting.

image

Here's the repository to reproduce the issue: https://github.com/tsuemura/codeceptjs-playwright-device-bug-reproduction

What do you get instead?

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

$ npm install
$ npx codeceptjs run

CodeceptJS v3.5.11 #StandWithUkraine
Using test root "/Users/takuyasuemura/ghq/github.com/tsuemura/codeceptjs-playwright-device-bug-reproduction"

Repro --
sessionScreen is {"width":1280,"height":720}
  ✖ Reproduce issue in 2433ms

-- FAILURES:

  1) Repro
       Reproduce issue:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(sessionScreen.width === 375)

      + expected - actual

      -false
      +true


  Artifacts:
  - screenshot: /Users/takuyasuemura/ghq/github.com/tsuemura/codeceptjs-playwright-device-bug-reproduction/output/Reproduce_issue.failed.png


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

Provide test source code if related

Test code

const assert = require('assert/strict')

Feature('Repro')

Scenario('Reproduce issue', async ({ I }) => {
  I.amOnPage('https://example.com')
  
  session('user1', async () => {
    I.amOnPage('https://www.google.com')
    const sessionScreen = await I.executeScript(() => {
      return { width: window.screen.width, height: window.screen.height };
    })
    console.log(`sessionScreen is ${JSON.stringify(sessionScreen)}`)

    // iPhone 6 is 375x667
    assert(sessionScreen.width === 375)
    assert(sessionScreen.height === 667)
  })

})

Details

  • CodeceptJS version: "3.5.11"
  • NodeJS Version: v18.15.0
  • Operating System: MacOS Ventura 13.3.1
  • puppeteer || webdriverio || testcafe version (if related): Playwright 1.40.1
  • Configuration file:

codecept.conf.js

const { setHeadlessWhen, setCommonPlugins } = require("@codeceptjs/configure");
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

const { devices } = require("playwright");

/** @type {CodeceptJS.MainConfig} */
exports.config = {
  tests: "./*_test.js",
  output: "./output",
  helpers: {
    Playwright: {
      browser: "chromium",
      url: "http://localhost",
      show: true,
      emulate: devices["iPhone 6"],
    },
  },
  include: {
    I: "./steps_file.js",
  },
  name: "codeceptjs-playwright-device-bug-reproduction",
};
@kobenguyent
Copy link
Collaborator

hi @tsuemura just in case you haven't noticed this useful helper from codeceptjs - instead of requiring assert/expect lib
https://codecept.io/helpers/Expect/#expectequal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants