diff --git a/e2e/e2e.spec.js b/e2e/e2e.spec.js index d1aeb8252b..9862189fb8 100644 --- a/e2e/e2e.spec.js +++ b/e2e/e2e.spec.js @@ -10,48 +10,79 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000 // Set timeout describe('e2e', () => { let nightmare let server + const extractSpyResult = () => { + return [ + window.normalVerifyCallback.calledOnce, + window.bindedVerifyCallback.calledOnce, + window.invisibleVerifyCallback.calledOnce + ] + } - it('work', async () => { - const spyResult = await nightmare - .goto('http://localhost:8080/e2e/index.html') - .wait(1000) // Wait for recaptcha loaded - .enterIFrame('iframe[name=undefined]') - .click('.recaptcha-checkbox') - .exitIFrame() - .wait(3000) // Wait for verified - .evaluate(() => { - return window.verifyCallback.calledOnce - }) + describe('Normal reCAPTCHA', () => { + it('work', async () => { + let spyResult = await nightmare + .enterIFrame('iframe[name=undefined]') + .click('.recaptcha-checkbox') + .exitIFrame() + .wait(2000) // Wait for verified + .evaluate(extractSpyResult) - expect(spyResult).toBe(true) + expect(spyResult).toEqual([true, false, false]) + }) + }) + + describe('Binded reCAPTCHA', () => { + it('work', async () => { + let spyResult = await nightmare + .click('#binded') + .wait(2000) // Wait for verified + .evaluate(extractSpyResult) + + expect(spyResult).toEqual([false, true, false]) + }) + }) + + describe('Invisible reCAPTCHA', () => { + it('work', async () => { + let spyResult = await nightmare + .click('#submit') + .wait(2000) // Wait for verified + .evaluate(extractSpyResult) + + expect(spyResult).toEqual([false, false, true]) + }) }) beforeAll(() => { // Setup http-server + nightmare = new Nightmare({ + webPreferences: { + webSecurity: false // Need for access iframe + } + }) + + const nightmareInitial = nightmare + .goto('http://localhost:8080/e2e/index.html') + .wait(1000) // Wait for recaptcha loaded + return new Promise((resolve) => { server = HttpServer.createServer({ root: path.resolve(__dirname, '..') }) - server.listen(8080, () => { + server.listen(8080, async () => { + await nightmareInitial resolve() }) }) }) beforeEach(() => { - nightmare = new Nightmare({ - webPreferences: { - webSecurity: false // Need for access iframe - } - }) - }) - - afterEach(() => { - return nightmare.end() + return nightmare.evaluate(() => window.resetSpies()) }) afterAll(() => { server.close() + return nightmare.end() }) }) diff --git a/e2e/index.html b/e2e/index.html index 4fd10fb4c8..6fa60a35d4 100644 --- a/e2e/index.html +++ b/e2e/index.html @@ -6,16 +6,32 @@ -

This is example to use vue-recaptcha

- - - +
+ + +
+
+ + + +
+
+
+ + + +
+