Skip to content

Instantly share code, notes, and snippets.

@IhostVlad
Created June 17, 2019 10:39
Show Gist options
  • Save IhostVlad/7aaf5268712d49407ebea0a056ab6cd6 to your computer and use it in GitHub Desktop.
Save IhostVlad/7aaf5268712d49407ebea0a056ab6cd6 to your computer and use it in GitHub Desktop.
hackernews-stress
import { Selector } from 'testcafe'
const ROOT_URL = `https://jd05ienjxfkjegg8mim64t8z1e.resolve.sh`
const roundSeed = `${Date.now()}-${Math.floor(Math.random()*100000000000)}`
fixture`Testcafe stress`
test('Testcafe stress test', async (t) => {
await t.setNativeDialogHandler(() => true)
{
await t.navigateTo(`${ROOT_URL}/login`)
await t.typeText(await Selector('input[type=text]').nth(2), `User-${roundSeed}`)
await t.click(await Selector('input[type=submit]').nth(1))
}
{
await t.navigateTo(`${ROOT_URL}/submit`)
await t.typeText(Selector('input[type=text]').nth(1), `Ask-${roundSeed}`)
await t.typeText('textarea', Array.from({ length: 50 }).map(_ => roundSeed).join(','))
await t.click('button')
}
{
await t.navigateTo(`${ROOT_URL}/newest`)
const titleLink = await Selector('a').withText(`Ask HN: Ask-${roundSeed}`)
await t.click(titleLink)
await t.wait(5000)
}
{
const textarea = await Selector('textarea').nth(-1)
await t.typeText(textarea, 'first comment')
const button = await Selector('button').nth(-1)
await t.click(button)
await t.wait(5000)
}
{
await t.navigateTo(`${ROOT_URL}/newest`)
await t.click(await Selector('a').withText(`Ask HN: Ask-${roundSeed}`).nth(-1))
await t.wait(5000)
await t.click(await Selector('a').withText('reply').nth(-1))
await t.wait(5000)
}
{
const textarea = await Selector('textarea').nth(-1)
await t.typeText(textarea, Array.from({ length: 50 }).map(_ => roundSeed).join(','))
const button = await Selector('button').nth(-1)
await t.click(button)
await t.wait(5000)
}
})
{
"name": "example",
"version": "0.0.2",
"license": "MIT",
"dependencies": {
"testcafe": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment