E2E Transporter - How to manage a database?

I currently rely on the Node + Angular stack and use Karma and Protractor for testing.

Currently, it’s hard for me to understand how to handle E2E tests that create and edit data, as well as the need to load the expected data.

A google search opens up many different custom methods. I often read β€œyou need to customize your data” or β€œjust create a layout” without going into details about the overall process. Others have invested too much overhead in creating a completely new breadboard module from scratch.

I just wanted to know how people do it now, and is there a standard for this? Or do people tend to just mock the inner end? Mocking the content does not seem simple, as in Karma, because you are in the browser area.

I, as expected, used MongoDB, so it would be nice to get some direction regarding what others are doing in this scenario. Especially automated loading of fixtures and cleaning the database through Protractor would be good.

+10
angularjs unit-testing protractor angularjs-e2e
source share
3 answers

The protractor is for e2e testing only. this means that it has nothing to do with your database. you can use the task runner (e.g. grunt or gulp) to clean and populate your database, after which let the task runner run your protractor tests (I never did the latter, but I think it is possible). well, I know that this is not the answer you were striving for, but perhaps I could point you in the right direction.

0
source share

You can manage your database through the REST API (web service).

I want to show an example of how to remove a user from a database using a web service with a protractor. In my example, I use Oracle as a database.

class OracleDatabaseAccess { private readonly BASE_API_URL: string = browser.params.someUrlToYourRest; public request<T>(query: string): promise.Promise<T[]> { return this.get<T[]>(this.BASE_API_URL, 'sql?query=' + this.fixQuery(query)); } public update<T>(query: string): promise.Promise<T[]> { return this.get<T[]>(this.BASE_API_URL, 'update?query=' + this.fixQuery(query)); } public get<T>(url: string, path: string): promise.Promise<T> { const http = new HttpClient(url); http.failOnHttpError = true; const responsePromise: ResponsePromise = http.get(path); return responsePromise.body.then(body => { return JSON.parse(body.toString()); }) as promise.Promise<T>; } private fixQuery(query: string): string { if (query.includes('%')) { query = query.split('%').join('%25'); } if (query.includes(';')) { query = query.replace(';', ''); } return query; } } class Queries { private oracleDataBaseAccess: OracleDatabaseAccess = new OracleDatabaseAccess(); deleteUser(userId: string): promise.Promise<{}> { return this.oracleDataBaseAccess.update('delete from users where userId='${userId}''); } } 

Using the request method, you can select records from the database. Also, using the update method, you can insert data.

You can use Queries in describe in beforeAll or afterAll . For example, in beforeAll you create some users, and in afterAll you delete them.

0
source share

Basically, you will let you create a separate testing environment for end-to-end tests.

Where after each execution of the text you need to reload your database with a database reset script

0
source share

All Articles