2014-10-21 3 views
0

현재 내 자동화 프레임 워크는 cucumberJS의 각도기를 사용합니다. 우리는 주장 라이브러리 (assertion library)로 약속 한대로 chai를 사용하며, 최근에는 데이터베이스에 대해 직접적인 mysql 쿼리를 수행해야 할 필요성을 느꼈다.각도기 + CucumberJS MySQL 쿼리

단계 정의를 구성하여 쿼리를 가져올 수 있고 같은 단계 내에서 쿼리 결과를 사용할 수 있습니까? 내 현재의 투쟁은 비동기 방식의 분도기가 실행되어 쿼리 결과가 필요한 단계 후에도 쿼리를 수행하게하고 쿼리의 결과로 생성 된 JSON 개체를 전달할 범위도 결정하게됩니다.

this.loginWithMysqlUser = function(uname) { 
var mysql = require('mysql'); 
var connection = mysql.createConnection({ 
    host : 'localhost', 
    user : '*******', 
    password : '*******', 
    database : '*******' 
}); 

    connection.connect(); 

    connection.query('SELECT * FROM prot_users WHERE username = ?', [uname], function(err, rows) { 
    if(err) throw err; 

    mysqlUser = { 
     username: rows[0].username, 
     password: rows[0].password 
    }; 

    }); 

    connection.end(); 

    loginpage.login(mysqlUser); 

    }; 

이 함수는 loginpage 선언에 있습니다.

답변

0

connection.query 함수 내에서 데이터로 작업해야하는 로그인 및 함수에 대한 모든 논리가 포함되어 있습니다.

잘 작동하는 것으로 보이며 각도기는 해당 쿼리 기능 내에서 호출 할 수있었습니다.

1

그래서 일반적으로 오이 테스트 스크립트는 원하는 :

Given(/^that I am logged in as admin$/, function(callback){ 
    .. 
    logic goes here 
    .. 
}); 
And(/^I wish to check that customer (foo) is registered$/, 
function(username, callback){ 
    // create connection with db as described 
    // with supplied username 
    // Use a promise to create mySQL connection 
    // and queries DB based on username as described 
    // on successful resolution set DBResult to results 
    // for username, password and database 
    // on error set DBResult to undefined 
}); 
Then(/^I expect following details from DB query$/, function(data, 
callback) 
{ 
    var rows = data.raw; 
    // extract values of input table cells into DBExpect using 
    // rows[0].username 
    // rows[0].password 
    // rows[0].database 
    // Check equality of DBResult and DBExpect objects 
    .. 
    expect.isFulfilled(DBResult).toEqual(DBExpect).notify(callback); 
}); 
: 대한 단계 정의에

Feature: As an admin I would like to check if a customer has an  
     account 
Scenario: Check that customer name is registered in DB 
Given that I am logged in as admin 
And I wish to check that customer (foo) is registered 
Then I expect following details from DB query: 
    | username | password | database | 
    | foo  | bar  | mysql |