-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): focus and xpath dom extenders
- Loading branch information
1 parent
fd4b7ff
commit 0888c8b
Showing
9 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Helpers } from '@ulixee/hero-testing'; | ||
import { ITestKoaServer } from '@ulixee/hero-testing/helpers'; | ||
import Hero from '../index'; | ||
|
||
let koaServer: ITestKoaServer; | ||
beforeAll(async () => { | ||
koaServer = await Helpers.runKoaServer(); | ||
}); | ||
afterAll(Helpers.afterAll); | ||
afterEach(Helpers.afterEach); | ||
|
||
describe('basic DomExtender tests', () => { | ||
it('can run xpathSelector', async () => { | ||
koaServer.get('/domextender-xpath', ctx => { | ||
ctx.body = ` | ||
<body> | ||
<h2>here</h2> | ||
</body> | ||
`; | ||
}); | ||
const hero = await openBrowser(`/domextender-xpath`); | ||
|
||
await expect(hero.xpathSelector('//h2').textContent).resolves.toBe('here'); | ||
}); | ||
|
||
it('can run xpathSelectorAll', async () => { | ||
koaServer.get('/domextender-xpath-all', ctx => { | ||
ctx.body = ` | ||
<body> | ||
<h2>here 1</h2> | ||
<h2>here 2</h2> | ||
<h2>here 3</h2> | ||
</body> | ||
`; | ||
}); | ||
const hero = await openBrowser(`/domextender-xpath-all`); | ||
|
||
const xpathAll = await hero.xpathSelectorAll('//h2'); | ||
|
||
let counter = 0; | ||
for (const entry of xpathAll) { | ||
counter += 1; | ||
await expect(entry.textContent).resolves.toBe(`here ${counter}`); | ||
} | ||
}); | ||
|
||
it('can find the focused field', async () => { | ||
koaServer.get('/domextender-focused', ctx => { | ||
ctx.body = `<body><input id="field" type="text"/></body>`; | ||
}); | ||
const hero = await openBrowser(`/domextender-focused`); | ||
await expect(hero.querySelector('#field').$hasFocus).resolves.toBe(false); | ||
await expect(hero.querySelector('#field').$click()).resolves.toBe(undefined); | ||
await expect(hero.querySelector('#field').$hasFocus).resolves.toBe(true); | ||
}); | ||
}); | ||
|
||
async function openBrowser(path: string) { | ||
const hero = new Hero(); | ||
Helpers.needsClosing.push(hero); | ||
await hero.goto(`${koaServer.baseUrl}${path}`); | ||
await hero.waitForPaintingStable(); | ||
return hero; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters