UNPKG

playwright-fluent

Version:
175 lines (174 loc) 6.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const SUT = tslib_1.__importStar(require("../../playwright-fluent")); describe('Playwright Fluent - expect has class', () => { let p; beforeEach(() => { p = new SUT.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should throw on a non existing selector - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = 'foobar'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasClass('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector 'foobar' was not found in DOM."); }); test('should throw on a non existing selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = p.selector('foobar'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasClass('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector 'selector(foobar)' was not found in DOM."); }); test('should throw when selector has no class - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = '#input-with-no-class'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasClass('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector '#input-with-no-class' does not have class 'yo', because no class has been found on the selector"); }); test('should throw when selector object has no class - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = p.selector('input').withValue('input with no class'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasClass('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain(`'selector(input) .withValue(input with no class)' does not have class 'yo', because no class has been found on the selector`); }); test('should throw when selector does not have the class - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = '#dynamically-added-input'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasClass('yo', { timeoutInMilliseconds: 4000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector '#dynamically-added-input' does not have class 'yo', but instead has classes 'foo,bar,baz'"); }); test('should throw when selector object does have the class - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = p.selector('input').withValue('dynamically added'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasClass('yo', { timeoutInMilliseconds: 4000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain(`'selector(input) .withValue(dynamically added)' does not have class 'yo', but instead has classes 'foo,bar,baz'`); }); test('should wait until selector has expected class - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = '#dynamically-added-input'; // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .hover(selector) .expectThatSelector(selector) .hasClass('foo'); // THEN }); test('should wait until selector object has expected class - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-class.test.html')}`; const selector = p.selector('input').withValue('dynamically added input'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .hover(selector) .expectThatSelector(selector) .hasClass('foo'); // THEN const classList = await selector.classList(); expect(classList).toContain('foo'); }); });