Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder committed Mar 11, 2020
1 parent 1a9f334 commit 7b85635
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
5 changes: 3 additions & 2 deletions utils/generate_types/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Handle<T> = T extends Node ? ElementHandle<T> : JSHandle<T>;
type ElementHandleForTag<K extends keyof HTMLElementTagNameMap> = ElementHandle<HTMLElementTagNameMap[K]>;

type WaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
visibility: 'visible'|'any';
waitFor: 'visible'|'attached';
}

type HTMLOrSVGElement = SVGElement | HTMLElement;
Expand Down Expand Up @@ -127,4 +127,5 @@ export interface ChromiumSession {
): Promise<Protocol.CommandReturnValues[T]>;
}

export type Devices = {[name: string]: {viewport: BrowserNewContextOptionsViewport, userAgent: string}};
type DeviceDescriptor = {viewport: BrowserNewContextOptionsViewport, userAgent: string};
export type Devices = {[name: string]: DeviceDescriptor} & DeviceDescriptor[];
29 changes: 21 additions & 8 deletions utils/generate_types/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ playwright.chromium.launch().then(async browser => {

let currentURL: string;
page
.waitForSelector('img', { visibility: 'visible' })
.waitForSelector('img', { waitFor: 'visible' })
.then(() => console.log('First URL with image: ' + currentURL));
for (currentURL of [
'https://example.com',
Expand Down Expand Up @@ -418,8 +418,8 @@ playwright.chromium.launch().then(async browser => {
const numberAssertion: AssertType<number, typeof x> = true;
}, 5);

const something = Math.random() > .5 ? 'visible' : 'any';
const handle = await page.waitForSelector('a', {visibility: something});
const something = Math.random() > .5 ? 'visible' : 'attached';
const handle = await page.waitForSelector('a', {waitFor: something});
await handle.$eval('span', (element, x, y) => {
const spanAssertion: AssertType<HTMLSpanElement, typeof element> = true;
const numberAssertion: AssertType<number, typeof x> = true;
Expand Down Expand Up @@ -479,11 +479,16 @@ playwright.chromium.launch().then(async browser => {
const canBeNull: AssertType<null, typeof handle> = false;
}
{
const visibility = Math.random() > .5 ? 'any' : 'visible';
const handle = await frameLike.waitForSelector('body', {visibility});
const waitFor = Math.random() > .5 ? 'attached' : 'visible';
const handle = await frameLike.waitForSelector('body', {waitFor});
const bodyAssertion: AssertType<playwright.ElementHandle<HTMLBodyElement>, typeof handle> = true;
const canBeNull: AssertType<null, typeof handle> = false;
}
{
const handle = await frameLike.waitForSelector('body', {waitFor: 'hidden'});
const bodyAssertion: AssertType<playwright.ElementHandle<HTMLBodyElement>, typeof handle> = true;
const canBeNull: AssertType<null, typeof handle> = true;
}
{
const waitFor = Math.random() > .5 ? 'hidden' : 'visible';
const handle = await frameLike.waitForSelector('body', {waitFor});
Expand All @@ -497,8 +502,8 @@ playwright.chromium.launch().then(async browser => {
const canBeNull: AssertType<null, typeof handle> = false;
}
{
const visibility = Math.random() > .5 ? 'any' : 'visible';
const handle = await frameLike.waitForSelector('something-strange', {visibility});
const waitFor = Math.random() > .5 ? 'attached' : 'visible';
const handle = await frameLike.waitForSelector('something-strange', {waitFor});
const elementAssertion: AssertType<playwright.ElementHandle<HTMLElement|SVGElement>, typeof handle> = true;
const canBeNull: AssertType<null, typeof handle> = false;
}
Expand All @@ -518,7 +523,15 @@ playwright.chromium.launch().then(async browser => {
(async () => {
playwright.chromium.connect;
playwright.errors.TimeoutError;
const iPhone = playwright.devices['iPhone'];
{
const iPhone = playwright.devices['iPhone'];
const assertion: AssertType<string, typeof iPhone.userAgent> = true;
const numberAssertion: AssertType<number, typeof iPhone.viewport.width> = true;
}
{
const agents = playwright.devices.map(x => x.userAgent);
const assertion: AssertType<string[], typeof agents> = true;
}

// Must be a function that evaluates to a selector engine instance.
const createTagNameEngine = () => ({
Expand Down

0 comments on commit 7b85635

Please sign in to comment.