Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Add ControlOrMeta helper key #1457

Merged
merged 3 commits into from
Oct 4, 2024
Merged

Add ControlOrMeta helper key #1457

merged 3 commits into from
Oct 4, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Oct 4, 2024

What?

This will allow us to write the test for all platforms that either work with Control or Meta when performing keyboard actions. E.g. Control+click on windows, and meta+click on mac to open a link in a new window.

Why?

It allows us to do the following on windows, linux and mac without checking which platform the script is ran on in the test script itself to choose the correct meta key (control or meta):

import { browser } from "k6/browser";

export const options = {
  scenarios: {
    ui: {
      executor: "shared-iterations",
      options: {
        browser: {
          type: "chromium",
        },
      },
    },
  }
};

export default async function () {
  const page = await browser.newPage();

  await page.goto("https://test.k6.io/");
  
  await page.keyboard.down('ControlOrMeta');

  // Open the link in a new tab.
  // Wait for the new page to be created.
  const browserContext = browser.context();
  const [newTab] = await Promise.all([
    browserContext.waitForEvent('page'),
    await page.locator('a[href="/my_messages.php"]').click()
  ]);

  await page.keyboard.up('ControlOrMeta');

  // Wait for the new page (tab) to load.
  await newTab.waitForLoadState('load');

  // Take screenshots of each page.
  await page.screenshot({ path: `screenshot-page.png` });
  await newTab.screenshot({ path: `screenshot-newTab.png` });

  await newTab.close();
  await page.close();
}

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

tests/keyboard_test.go Outdated Show resolved Hide resolved
This will allow us to write the test for all platforms that either work
with Control or Meta when performing keyboard actions. E.g.
Control+click on windows, and meta+click on mac to open a link in a new
window.
@ankur22 ankur22 force-pushed the add/control-or-meta branch from 9482a47 to 20cbe3b Compare October 4, 2024 09:34
@ankur22 ankur22 requested a review from inancgumus October 4, 2024 09:34
@ankur22 ankur22 mentioned this pull request Oct 4, 2024
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

tests/keyboard_test.go Outdated Show resolved Hide resolved
@ankur22 ankur22 force-pushed the add/control-or-meta branch from a106f45 to 75aac40 Compare October 4, 2024 16:30
The test now doesn't test with combo keys which doesn't work yet.
Instead we're using dblClick.
@ankur22 ankur22 force-pushed the add/control-or-meta branch from 75aac40 to 47ac4c0 Compare October 4, 2024 16:34
@ankur22 ankur22 requested a review from inancgumus October 4, 2024 17:12
@ankur22 ankur22 merged commit 50be4e4 into main Oct 4, 2024
23 checks passed
@ankur22 ankur22 deleted the add/control-or-meta branch October 4, 2024 17:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants