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

Commit

Permalink
Merge pull request #56 from grafana/fix/46
Browse files Browse the repository at this point in the history
Fix colorscheme example
  • Loading branch information
inancgumus authored Nov 4, 2021
2 parents ec0652b + 69b042f commit 8b56cdc
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions examples/colorscheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ import launcher from 'k6/x/browser';
import { check } from 'k6';

export default function() {
const preferredColorScheme = 'dark';

const browser = launcher.launch('chromium', {
// FIXME: colorScheme doesn't actually work... The page loads in light mode
// regardless of the colorScheme value.
// See https://github.com/grafana/xk6-browser/issues/46
colorScheme: 'dark', // Valid values are "light", "dark" or "no-preference"
headless: __ENV.XK6_HEADLESS ? true : false,
});
const context = browser.newContext();

const context = browser.newContext({
// valid values are "light", "dark" or "no-preference"
colorScheme: preferredColorScheme,
});
const page = context.newPage();
page.goto('https://googlechromelabs.github.io/dark-mode-toggle/demo/', { waitUntil: 'load' });
const el = page.$('#dark-mode-toggle-3');

// FIXME: getAttribute() fails with:
// unable to get node ID of element handle *dom.RequestNodeParams
// See https://github.com/grafana/xk6-browser/issues/47
// check(el, {
// 'color scheme': e => e.getAttribute('mode') == 'dark',
// });
page.goto(
'https://googlechromelabs.github.io/dark-mode-toggle/demo/',
{ waitUntil: 'load' },
);

const colorScheme = page.evaluate(() => {
return {
isDarkColorScheme: window.matchMedia('(prefers-color-scheme: dark)').matches
};
});
check(colorScheme, {
'isDarkColorScheme': cs => cs.isDarkColorScheme
});

page.close();
browser.close();
Expand Down

0 comments on commit 8b56cdc

Please sign in to comment.