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.
Hidberg
source share