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

Refactor/breaking dependency cycles #202

Merged
merged 7 commits into from Jul 8, 2020
7 changes: 6 additions & 1 deletion packages/core/index.ts
Expand Up @@ -92,7 +92,12 @@ export const ENV: FloodProcessEnv = nullFloodProcessEnv
/**
* @docPage Browser
*/
export { Browser, Browser as Driver, Locatable, NullableLocatable } from './src/runtime/types'
export { Browser, Browser as Driver } from './src/runtime/IBrowser'

/**
* @docPage Browser
*/
export { Locatable, NullableLocatable } from './src/runtime/Locatable'

/**
* @docPage Browser
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/page/Condition.ts
Expand Up @@ -3,7 +3,7 @@ import { Locator } from './types'
import { DEFAULT_SETTINGS } from '../runtime/Settings'
import recast from 'recast'
import { locatableToLocator } from '../runtime/toLocatorError'
import { NullableLocatable } from '../runtime/types'
import { NullableLocatable } from '../runtime/Locatable'

import debugFactory from 'debug'
const debug = debugFactory('element:page:condition')
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/page/ElementHandle.ts
Expand Up @@ -18,7 +18,6 @@ import { Key } from './Enums'
import debugFactory from 'debug'
import { Point } from './Point'
import { CSSLocator } from './locators/index'
import { BaseLocator } from './Locator'
// import { By } from './Locators'
const debug = debugFactory('element:page:element-handle')

Expand Down Expand Up @@ -304,6 +303,7 @@ export class ElementHandle implements IElementHandle, Locator {
// TODO wrap
public async findElement(locator: string | Locator): Promise<IElementHandle | null> {
if (typeof locator === 'string') {
const { BaseLocator } = await import('./Locator')
locator = new BaseLocator(new CSSLocator(locator), 'handle.findElement')
}
return locator.find(this.element.executionContext(), this.element)
Expand All @@ -314,6 +314,7 @@ export class ElementHandle implements IElementHandle, Locator {
*/
public async findElements(locator: string | Locator): Promise<IElementHandle[]> {
if (typeof locator === 'string') {
const { BaseLocator } = await import('./Locator')
locator = new BaseLocator(new CSSLocator(locator), 'handle.findElements')
}
return locator.findMany(this.element.executionContext(), this.element)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/page/TargetLocator.ts
@@ -1,7 +1,7 @@
import { ElementHandle } from './ElementHandle'
import { Page, Frame } from 'puppeteer'
import { TargetLocator as ITargetLocator, ElementHandle as IElementHandle } from './types'
import { getFrames } from '../runtime/Browser'
import { getFrames } from '../utils/frames'

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/page/Until.ts
Expand Up @@ -13,7 +13,7 @@ import { URLCondition } from './conditions/URLCondition'
import { DialogCondition } from './conditions/DialogCondition'
import { FrameCondition } from './conditions/FrameCondition'
import { Condition } from './Condition'
import { NullableLocatable, Locatable } from '../runtime/types'
import { NullableLocatable, Locatable } from '../runtime/Locatable'
import { URLNotMatchCondition } from './conditions/URLNotMatchCondition'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/page/conditions/FrameCondition.ts
@@ -1,6 +1,6 @@
import { Condition, NullableLocatable } from '../Condition'
import { Frame, Page } from 'puppeteer'
import { getFrames } from '../../runtime/Browser'
import { getFrames } from '../../utils/frames'
import { setTimeout } from 'timers'

export class FrameCondition extends Condition {
Expand Down
18 changes: 4 additions & 14 deletions packages/core/src/runtime/Browser.ts
Expand Up @@ -8,9 +8,11 @@ import {
ScreenshotOptions,
AuthOptions,
Viewport,
EvaluateFn,
} from 'puppeteer'
import DeviceDescriptors from 'puppeteer/DeviceDescriptors'
import { Browser as BrowserInterface, NullableLocatable, EvaluateFn } from './types'
import { Browser as BrowserInterface } from './IBrowser'
import { NullableLocatable } from './Locatable'
import CustomDeviceDescriptors from '../utils/CustomDeviceDescriptors'
import { ElementHandle } from '../page/types'
import { TargetLocator } from '../page/TargetLocator'
Expand All @@ -29,23 +31,11 @@ import { addCallbacks } from './decorators/addCallbacks'
import { autoWaitUntil } from './decorators/autoWait'
import { locatableToLocator, toLocatorError } from './toLocatorError'
import { Keyboard } from '../page/Keyboard'
import { getFrames } from '../utils/frames'

export const debug = debugFactory('element:runtime:browser')
const debugScreenshot = debugFactory('element:runtime:browser:screenshot')

export const getFrames = (childFrames: Frame[], collection?: Set<Frame>): Frame[] => {
if (typeof collection === 'undefined') collection = new Set<Frame>()

childFrames.forEach(frame => {
if (!collection?.has(frame)) {
collection?.add(frame)
getFrames(frame.childFrames(), collection)
}
})

return Array.from(collection.values())
}

export class Browser<T> implements BrowserInterface {
public screenshots: string[]
customContext: T
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/runtime/EvaluatedScript.ts
Expand Up @@ -19,7 +19,8 @@ import {
RecoverWith,
extractStep,
} from './Step'
import { SuiteDefinition, Browser } from './types'
import { SuiteDefinition } from './types'
import { Browser } from './IBrowser'
import Test from './Test'
import { mustCompileFile } from '../TestScript'
import { TestScriptError, TestScriptErrorMapper } from '../TestScriptError'
Expand Down