diff --git a/Production/RAMMIT-Stable/Tests/TestUi.mjs b/Production/RAMMIT-Stable/Tests/TestUi.mjs index bda796f..55c37e2 100644 --- a/Production/RAMMIT-Stable/Tests/TestUi.mjs +++ b/Production/RAMMIT-Stable/Tests/TestUi.mjs @@ -126,8 +126,7 @@ try { Check('launch button counts', (await Text('#LaunchBtn')) === 'LAUNCH 4 SELECTED'); await Page.click('#SelectAllBtn'); await Wait(150); Check('clear all', await Count('#AccountList .Selected') === 0); - const Persisted = await CallApi('GetSettings'); - Check('selection persisted by username', Array.isArray(Persisted.SelectedAccounts) && Persisted.SelectedAccounts.length === 0); + Check('selection persisted by username', await WaitFor(async () => Array.isArray((await CallApi('GetSettings')).SelectedAccounts) && (await CallApi('GetSettings')).SelectedAccounts.length === 0)); // ------------------------------------------------------------ launching await Pick('LaunchOptionSelect', 'Home'); @@ -167,8 +166,8 @@ try { await Page.click('#SaveSettingsBtn'); await Wait(200); Check('max instances 0 rejected', /1 to 100/.test(await Text('#StatusMessage')), await Text('#StatusMessage') + ' / ' + await Page.$eval('#MaxInstances', E => E.value)); await SetValue(Page, '#MaxInstances', '10'); - await Page.click('#SaveSettingsBtn'); await Wait(300); - Check('settings saved', (await Text('#StatusMessage')) === 'Settings saved' && (await CallApi('GetSettings')).MaxInstances === 10); + await Page.click('#SaveSettingsBtn'); + Check('settings saved', await WaitFor(async () => (await Text('#StatusMessage')) === 'Settings saved' && (await CallApi('GetSettings')).MaxInstances === 10)); Check('backend rejects bad types', !!(await CallApi('UpdateSetting', 'MaxInstances', 'lots')).Error && !!(await CallApi('UpdateSetting', 'Bogus', 1)).Error); await SetValue(Page, '#ChannelEntry', 'bad channel!'); await Page.click('#SaveChannelBtn'); await Wait(250); @@ -176,8 +175,8 @@ try { await SetValue(Page, '#ChannelEntry', 'zbeta'); await Page.click('#SaveChannelBtn'); await Wait(250); Check('valid channel saved', (await Text('#StatusMessage')) === 'Channel updated', await Text('#StatusMessage')); - await Page.click('#SettingsToggle'); await Wait(450); - Check('settings fold away', await Page.$eval('#SettingsPanel', E => E.classList.contains('Collapsed')) && (await CallApi('GetSettings')).SettingsCollapsed === true); + await Page.click('#SettingsToggle'); + Check('settings fold away', await WaitFor(async () => (await Page.$eval('#SettingsPanel', E => E.classList.contains('Collapsed'))) && (await CallApi('GetSettings')).SettingsCollapsed === true)); await Page.click('#SettingsToggle'); await Wait(450); // ------------------------------------------------------------ configs + wizard @@ -232,9 +231,9 @@ try { // ------------------------------------------------------------ themes Check('theme list has 4 themes', await Count('#ThemeSelect .CustomSelectOption') === 4 && await Count('#ThemeSelect .CustomSelectOption .ThemeSwatch') === 4 && await Count('#ThemeSelect .CustomSelectText .ThemeSwatch') === 0 && !!(await Page.$('#ActiveThemeSwatch'))); const DarkBg = await Bg(); - await Promise.all([Page.waitForNavigation({ waitUntil: 'load' }), Pick('ThemeSelect', 'Light')]); await Wait(900); - Check('Light theme loads', (await Bg()) === 'rgb(228, 228, 228)' && (await Text('#ThemeSelect .CustomSelectText')) === '2016 Roblox', await Bg()); - Check('Light uses its own stylesheet', await Page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--Accent').trim()) === '#00a2ff'); + await Promise.all([Page.waitForNavigation({ waitUntil: 'load' }), Pick('ThemeSelect', 'Light')]); + Check('Light theme loads', await WaitFor(async () => (await Bg()) === 'rgb(228, 228, 228)' && (await Text('#ThemeSelect .CustomSelectText')) === '2016 Roblox'), await Bg()); + Check('Light uses its own stylesheet', await WaitFor(async () => (await Page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--Accent').trim())) === '#00a2ff')); await Shot('03-Light'); await Promise.all([Page.waitForNavigation({ waitUntil: 'load' }), Pick('ThemeSelect', 'MyCustomTheme')]); await Wait(900); Check('MyCustomTheme loads', (await Bg()) === 'rgb(13, 15, 26)', await Bg()); diff --git a/Production/RAMMIT-Stable/Tests/TestUiWaits.py b/Production/RAMMIT-Stable/Tests/TestUiWaits.py new file mode 100644 index 0000000..f740fd4 --- /dev/null +++ b/Production/RAMMIT-Stable/Tests/TestUiWaits.py @@ -0,0 +1,34 @@ +import pathlib +import unittest + +# The headless UI test must poll (WaitFor) for these checks, not sleep a fixed time, or it flakes on a busy PC. +POLLED_CHECKS = [ + 'selection persisted by username', + 'settings saved', + 'settings fold away', + 'Light theme loads', + 'Light uses its own stylesheet', +] + +UI_TEST = pathlib.Path(__file__).with_name('TestUi.mjs') + + +class TestUiWaits(unittest.TestCase): + def test_polled_checks_use_waitfor_without_fixed_sleep(self): + lines = UI_TEST.read_text(encoding='utf-8').splitlines() + for label in POLLED_CHECKS: + with self.subTest(check=label): + start = f"Check('{label}'" + matches = [index for index, line in enumerate(lines) if start in line] + self.assertEqual(len(matches), 1, f"expected one line for {label}") + index = matches[0] + self.assertIn('WaitFor(', lines[index], f"Check '{label}' does not poll with WaitFor") + # The steps since the previous Check must not sleep a fixed time before this one looks. + for before in reversed(lines[:index]): + if 'Check(' in before: + break + self.assertNotIn('Wait(', before, f"Check '{label}' still has a fixed Wait() before it") + + +if __name__ == '__main__': + unittest.main()