How to use t.context.driver.close method in ava

Best JavaScript code snippet using ava

server.spec.js

Source:server.spec.js Github

copy

Full Screen

1import { createTestClient } from 'apollo-server-testing';2import { ApolloServer } from 'apollo-server';3import Server from '../src/server';4import actualContext from '../src/context';5import neode from '../src/db/neode';6import User from '../src/db/entities/User';7import Post from '../src/db/entities/Post';8import { LOGIN_USER, POSTS, SIGNUP_USER, UPVOTE_POST, USERS, WRITE_POST } from "./server.spec.queries";9let query;10let mutate;11let reqMock;12const context = () => actualContext({ req: reqMock });13const alice = new User({14 name: 'Alice',15 email: 'alice@example.org',16 password: '1234'17});18const bob = new User({19 name: 'Bob',20 email: 'bob@example.org',21 password: '4321'22});23const bobsPost = new Post({ title: "bobsPost", author: bob })24const cleanDatabase = async() => {25 const { driver } = context();26 await driver27 .session()28 .writeTransaction(txc => txc.run('MATCH(n) DETACH DELETE n;'));29};30beforeEach(async() => {31 reqMock = { headers: { authorization: "" } };32 await cleanDatabase();33 const server = await Server(ApolloServer, { context });34 const testClient = createTestClient(server);35 ({ query, mutate } = testClient);36});37afterAll(async() => {38 await cleanDatabase();39 const { driver } = context();40 driver.close();41 neode.driver.close();42});43describe('TEST WITHOUT AUTHENTICATION HEADER', () => {44 beforeEach(async() => {45 reqMock = { headers: { authorization: "" } };46 await alice.save()47 await bob.save()48 await bobsPost.save()49 })50 describe('QUERY POSTS', () => {51 it('returns all posts', async() => {52 await expect(query({ query: POSTS }))53 .resolves54 .toMatchObject({55 errors: undefined,56 data: {57 posts: [{ title: bobsPost.title, id: expect.any(String) }]58 }59 })60 })61 })62 describe('QUERY USERS', () => {63 it('returns all users', async() => {64 await expect(query({ query: USERS }))65 .resolves66 .toMatchObject({67 errors: undefined,68 data: {69 users: [{ name: expect.any(String), email: expect.any(String), id: expect.any(String) },70 { name: expect.any(String), email: expect.any(String), id: expect.any(String) }71 ]72 }73 })74 })75 })76 describe('MUTATE WRITE POST', () => {77 const action = () => mutate({ mutation: WRITE_POST, variables: { title: 'New Post' } })78 it('responds with error message', async() => {79 await expect(action())80 .resolves81 .toMatchObject({82 errors: [new Error("Not Authorised!")]83 })84 })85 })86 describe('MUTATE UPVOTE POST', () => {87 const action = () => mutate({ mutation: UPVOTE_POST, variables: { id: bobsPost.id } })88 it('responds with error message', async() => {89 await expect(action())90 .resolves91 .toMatchObject({92 errors: [new Error("Not Authorised!")]93 })94 })95 })96 describe('MUTATE SIGNUP USER', () => {97 describe('signup with non existing e-mail', () => {98 const action = () => mutate({99 mutation: SIGNUP_USER,100 variables: { name: 'Hans', password: "123456789", email: "hans" }101 })102 it('responds with token', async() => {103 await expect(action())104 .resolves105 .toMatchObject({106 errors: undefined,107 data: {108 signup: expect.any(String),109 }110 })111 })112 })113 describe('signup with existing e-mail', () => {114 const action = () => mutate({115 mutation: SIGNUP_USER,116 variables: {...alice }117 })118 it('responds with error', async() => {119 await expect(action())120 .resolves121 .toMatchObject({122 errors: [new Error("Email already exist")]123 })124 })125 })126 describe('signup with password of length smaller than 8', () => {127 const action = () => mutate({128 mutation: SIGNUP_USER,129 variables: { name: 'Hans', password: "1234", email: "alice" }130 })131 it('responds with error message', async() => {132 await expect(action())133 .resolves134 .toMatchObject({135 errors: [new Error("Password must have at least 8 characters")]136 })137 })138 })139 })140 describe('MUTATE LOGIN USER', () => {141 describe('login with wrong credentials', () => {142 describe('login with non existing e-mail', () => {143 const action = () => mutate({144 mutation: LOGIN_USER,145 variables: { password: "123456789", email: "r3fegdbffwdasfcvdbf" }146 })147 it('responds with error message', async() => {148 await expect(action())149 .resolves150 .toMatchObject({151 errors: [Error("Email or password is wrong")],152 })153 })154 })155 describe('login with non existing password', () => {156 const action = () => mutate({157 mutation: LOGIN_USER,158 variables: { password: "123123124123545", email: "hans" }159 })160 it('responds with error message', async() => {161 await expect(action())162 .resolves163 .toMatchObject({164 errors: [Error("Email or password is wrong")],165 })166 })167 })168 describe('login with non existing password and email', () => {169 const action = () => mutate({170 mutation: LOGIN_USER,171 variables: { password: "fqwafcsgefs", email: "5142453524123" }172 })173 it('responds with error message', async() => {174 await expect(action())175 .resolves176 .toMatchObject({177 errors: [Error("Email or password is wrong")],178 })179 })180 })181 })182 describe('login with existing credentials', () => {183 const signup_action = () => mutate({184 mutation: SIGNUP_USER,185 variables: { name: 'Hans', password: "123456789", email: "hans" }186 })187 const login_action = () => mutate({188 mutation: LOGIN_USER,189 variables: { password: "123456789", email: "hans" }190 })191 it('responds with token', async() => {192 await signup_action()193 await expect(login_action())194 .resolves195 .toMatchObject({196 errors: undefined,197 data: {198 login: expect.any(String),199 }200 })201 })202 })203 })204})205describe('TEST WITH AUTHENTICATION HEADER', () => {206 let token207 beforeEach(async() => {208 await alice.save()209 await bob.save()210 await bobsPost.save()211 const login_action = () => mutate({212 mutation: LOGIN_USER,213 variables: {...alice }214 })215 const loginData = await login_action()216 token = loginData.data.login217 reqMock = { headers: { authorization: token } };218 })219 describe('MUTATE WRITE POST', () => {220 const action = () => mutate({221 mutation: WRITE_POST,222 variables: { title: 'New Post' }223 })224 it('responds with new post', async() => {225 await expect(action())226 .resolves227 .toMatchObject({228 data: {229 write: {230 title: 'New Post',231 author: {232 name: alice.name233 }234 }235 }236 })237 })238 })239 describe('MUTATE UPVOTE POST', () => {240 describe('upvote once', () => {241 const action = () => mutate({242 mutation: UPVOTE_POST,243 variables: { id: bobsPost.id }244 })245 it('responds with new post', async() => {246 await expect(action())247 .resolves248 .toMatchObject({249 data: {250 upvote: {251 id: bobsPost.id,252 votes: 1253 }254 }255 })256 })257 })258 describe('upvote twice', () => {259 const action = () => mutate({260 mutation: UPVOTE_POST,261 variables: { id: bobsPost.id }262 })263 it('responds with post with same votes', async() => {264 await expect(action())265 .resolves266 .toMatchObject({267 data: {268 upvote: {269 id: bobsPost.id,270 votes: 1271 }272 }273 })274 })275 })276 describe('upvote post not exist', () => {277 const action = () => mutate({278 mutation: UPVOTE_POST,279 variables: { id: "1231231241232" }280 });281 it('responds with error message', async() => {282 await action()283 await expect(action())284 .resolves285 .toMatchObject({286 errors: [Error("Post does not exist")],287 })288 })289 })290 })...

Full Screen

Full Screen

cuke.config.js

Source:cuke.config.js Github

copy

Full Screen

1const webdriver = require('selenium-webdriver');2const all = require('./steps/all.js');3module.exports = {4 steps: [5 all6 ],7 features: [8 './features/example.feature'9 ],10 options: {11 maxInstances: 112 },13 hooks: {14 //before: () => console.log('before'),15 //after: () => console.log('after'),16 beforeTest: ({context, test}) => {17 context.name = test.name;18 context.by = webdriver.By;19 context.until = webdriver.until;20 context.driver = new webdriver.Builder()21 .forBrowser('chrome')22 .usingServer('http://localhost:4444/wd/hub')23 .build();24 return context.driver.manage().window().maximize();25 },26 afterTest: (data) => {27 return data.context.driver.close();28 },29 //testPassed: () => console.log('testPassed'),30 //testFailed: () => console.log('testFailed'),31 //beforeStep: () => console.log('beforeStep'),32 //afterStep: () => console.log('afterStep'),33 //stepPassed: () => console.log('stepPassed'),34 //stepFailed: () => console.log('stepFailed')35 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import test from 'ava';2import webdriver from 'selenium-webdriver';3test.beforeEach(t => {4 t.context.driver = new webdriver.Builder()5 .forBrowser('firefox')6 .build();7});8test.afterEach.always(t => {9 t.context.driver.close();10});11test('test title', t => {12 t.context.driver.getTitle().then(title => {13 t.is(title, 'Google');14 });15});16test('test title 2', t => {17 t.context.driver.getTitle().then(title => {18 t.is(title, 'Google');19 });20});21test('test title 3', t => {22 t.context.driver.getTitle().then(title => {23 t.is(title, 'Google');24 });25});26test('test title 4', t => {27 t.context.driver.getTitle().then(title => {28 t.is(title, 'Google');29 });30});31test('test title 5', t => {32 t.context.driver.getTitle().then(title => {33 t.is(title, 'Google');34 });35});36test('test title 6', t => {37 t.context.driver.getTitle().then(title => {38 t.is(title, 'Google');39 });40});41test('test title 7', t => {42 t.context.driver.getTitle().then(title => {43 t.is(title, 'Google');44 });45});46test('test title 8', t => {47 t.context.driver.getTitle().then(title => {48 t.is(title, 'Google');49 });50});51test('test title 9', t => {52 t.context.driver.getTitle().then(title => {53 t.is(title, 'Google');54 });55});56test('test title 10', t => {57 t.context.driver.getTitle().then(title => {58 t.is(title, 'Google');59 });60});61test('test title 11', t => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import test from 'ava';2import {Builder, By, Key, until} from 'selenium-webdriver';3test.beforeEach(async t => {4 t.context.driver = await new Builder().forBrowser('chrome').build();5});6test('Test1', async t => {7 await t.context.driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);8 await t.context.driver.wait(until.titleIs('webdriver - Google Search'), 1000);9});10test.afterEach.always(async t => {11 await t.context.driver.close();12});

Full Screen

Using AI Code Generation

copy

Full Screen

1import test from 'ava';2import webdriver from 'ava-webdriver';3test.beforeEach(t => {4 t.context.driver = webdriver(t, { browser: 'chrome' });5});6test.afterEach.always(t => {7 t.context.driver.close();8});9test('Test', async t => {10 const title = await t.context.driver.getTitle();11 t.is(title, 'Google');12});

Full Screen

Using AI Code Generation

copy

Full Screen

1test.afterEach.always(async t => {2 await t.context.driver.close();3});4test.afterEach.always(async t => {5 await t.context.driver.close();6});7test.afterEach.always(async t => {8 await t.context.driver.close();9});10test.afterEach.always(async t => {11 await t.context.driver.close();12});13test.afterEach.always(async t => {14 await t.context.driver.close();15});16test.afterEach.always(async t => {17 await t.context.driver.close();18});19test.afterEach.always(async t => {20 await t.context.driver.close();21});22test.afterEach.always(async t => {23 await t.context.driver.close();24});25test.afterEach.always(async t => {26 await t.context.driver.close();27});28test.afterEach.always(async t => {29 await t.context.driver.close();30});31test.afterEach.always(async t => {32 await t.context.driver.close();33});34test.afterEach.always(async t => {35 await t.context.driver.close();36});37test.afterEach.always(async t => {38 await t.context.driver.close();39});40test.afterEach.always(async t => {41 await t.context.driver.close();42});43test.afterEach.always(async t =>

Full Screen

Using AI Code Generation

copy

Full Screen

1test('My first test', async t => {2 const driver = await new Builder().forBrowser('chrome').build();3 t.context.driver = driver;4 await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);5 await driver.wait(until.titleIs('webdriver - Google Search'), 1000);6 await driver.close();7});8test('My second test', async t => {9 const driver = await new Builder().forBrowser('chrome').build();10 t.context.driver = driver;11 await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);12 await driver.wait(until.titleIs('webdriver - Google Search'), 1000);13 await driver.close();14});15I have tried using the .findElement(By.tagName(tagName))

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful