Skip to content
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

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.
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
The test now doesn't test with combo keys which doesn't work yet.
Instead we're using dblClick.
@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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants