์ฌ๋ฌ๋ถ, ์๋
ํ์ธ์,
๋จ๊ณ ์ ์์์ ๋น๋๊ธฐ๋ฅผ ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
๋ด ์์ฉ ํ๋ก๊ทธ๋จ์ API ์ธํฐํ์ด์ค๋ฅผ ํตํด ๋ก๊ทธ์ธํ์ฌ ์ธ์ฆ ํ ํฐ์ ๊ฐ์ ธ์ค๋ ๊ฐ๋จํ ์๋๋ฆฌ์ค๊ฐ ์์ต๋๋ค.
๋ด ๊ธฐ๋ฅ ํ์ผ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
Feature: Login
Scenario: Login using api
Given I login to my account with my username and password
Then I should get an authorization token
|username|password|
|[email protected]|dev|
๋ด ๋จ๊ณ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค
defineSupportCode(({ Given, Then, setDefaultTimeout }) => {
const timeOut = 30000;
const baseSteps: BaseSteps = new BaseSteps();
setDefaultTimeout(timeOut);
// tslint:disable-next-line:only-arrow-functions
Given(/^I login to my account with my username and password$/, async (table: TableDefinition) => {
const userData = table.hashes();
const loginResponse = await baseSteps.loginUser(userData[0].username, userData[0].password);
console.log('Login response is ', loginResponse);
const statusCode = 302;
expect(await loginResponse.status).to.equal(statusCode);
});
Then(/^I should get an authorization token$/, async () => {
const authorizationHeader = await baseSteps.getAuthorizationHeader();
console.log('Auth Header', authorizationHeader);
expect(authorizationHeader).to.not.equal(null);
const orders = await fetch('url',
{
method: 'GET', headers: {
authorization: authorizationHeader
}
});
// tslint:disable-next-line:no-console
console.log(await orders.json());
});
});
BaseSteps.ts์ ๋์ฐ๋ฏธ ๊ธฐ๋ฅ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
async loginUser(userName: string, password: string): Promise<Response> {
const getSignInFormResponse = await fetch(this.getInitialRequestUrl(),
{
method: 'GET'
});
const form = <some-form-data>;
const loginResponse = await fetch(getSignInFormResponse.url,
{
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
body: form,
redirect: 'manual'
});
return loginResponse;
}
async getAuthorizationHeader() {
const tokenResponse = await fetch(this.getInitialRequestUrl(),
{
method: 'GET',
redirect: 'manual'
});
const tokenInfo = qs.parse(tokenResponse.headers.get('location'));
const authorizationHeader = `${tokenInfo.token_type} ${tokenInfo.access_token}`;
return authorizationHeader;
}
๋ด ์๋๋ฆฌ์ค๋ฅผ ์คํํ ๋ ๋ค์ ์ค๋ฅ์ ํจ๊ป ์คํจํฉ๋๋ค.
Error: function uses multiple asynchronous interfaces: callback and promise
๋ด ๊ธฐ๋ธ์ด ์์๋๋ ๋ผ์ธ์์
์ด ์ค๋ฅ๋ฅผ ์์ ํ๋๋ก ๋์์ฃผ์ธ์.
Given
๋จ๊ณ ์ ์์๋ table
์ธ์๊ฐ ์์ง๋ง ๊ธฐ๋ฅ ํ์ผ์๋ ํ
์ด๋ธ์ด ์์ต๋๋ค. Cucumber-js๋ ๋จ๊ณ ์ ์์ ์ธ์ ์๋ฅผ ๊ธฐ๋ฐ์ผ๋ก callback
์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธํฉ๋๋ค. ์ซ์๊ฐ ์ ๋ฌ๋ ์ธ์ ์๋ณด๋ค ํ๋ ๋ ๋ง์ ๊ฒฝ์ฐ ์ฝ๋ฐฑ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. ํ๋ผ๋ฏธ์ค๋ ๋ฐํํ๋ฏ๋ก ํ๋ผ๋ฏธ์ค ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธํฉ๋๋ค. ํ ๋ฒ์ ํ๋์ ์ธํฐํ์ด์ค๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋จ๊ณ ์ ์์ X๊ฐ์ ์ธ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ฝ๋ฐฑ ์ธํฐํ์ด์ค๊ฐ ๊ฐ์ ๋๋ค๋ ์ฌ์ค์ ๋ํ ๋ด์ฉ์ ํฌํจํ๋๋ก ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ ๋ํ ์๊ฐ์?
@charlierudolph Hey mate ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค. ๊ทธ๋ฐ๋ฐ ์ ๋ด ๊ธฐ๋ฅ ํ์ผ์ ํ ์ด๋ธ์ด ์๋ค๊ณ ๋ง์
Given I login to my account with my username and password
Then I should get an authorization token
|username|password|
|[email protected]|dev|
๊ธฐ๋ฅ ํ์ผ์์ ํ
์ด๋ธ์ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ์ด ์๋๊ฐ์?
์ฌ๊ธฐ์์ ์๊ฐ์ ์ป์์ต๋๋ค https://github.com/cucumber/cucumber-js/blob/master/features/data_tables.feature
์, ์ค๋ฅ ๋ฉ์์ง๊ฐ ์ข ๋ ๋ช
ํํ ์ ์์ต๋๋ค.
๋ค์ ํ๋ฒ ๊ฐ์ฌํฉ๋๋ค.
๊ธฐ๋ฅ ํ์ผ์์ Then
๋จ๊ณ์๋ ํ
์ด๋ธ์ด ์์ง๋ง Given
๋จ๊ณ์๋ ํ
์ด๋ธ์ด ์์ต๋๋ค.
์ด ์ ์ฅ.. ๋ค ๋ง์์.. ํ
์ด๋ธ์ example
์ฐฉ๊ฐํด์ ํผ๋์ ๋๋ ค ์ฃ์กํฉ๋๋ค. ์ด์ ๊ด์ฐฎ์ ๊ฒ ๊ฐ์์. ๋ฌธ์ ๊ฐ ์ง์๋๋ฉด ๋ค์ ์ง๋ฌธํ๊ธฐ ์ํด ๋ค์ ์ฌ ๊ฒ์
๋๋ค.
@charlierudolph๋ก ๋ฌธ์ ๋ฅผ ๋ซ๋ ๊ฒ์ ๊ธฐ๋ฅ ํ์ผ์์ ๋ด ์์ ์ ์ฝ๋ฉ ์ค๋ฅ๋ฅผ ํ์ ํ๋ ๋ฐ ๋์์ด ๋์์ต๋๋ค.
๋คํ์ ๋๋ค. ์ค๋ฅ ๋ฉ์์ง ์ ๋ฐ์ดํธ์ ๋ํ ๋ณ๋์ ๋ฌธ์ ๋ฅผ ์ด์ด ํฅํ ๋ ์ฝ๊ฒ ํ์ ํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์ด ์ค๋ ๋๋ ๋ซํ ํ ์ต๊ทผ ํ๋์ด ์์๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ์ ๊ฒผ์ต๋๋ค. ๊ด๋ จ ๋ฒ๊ทธ์ ๋ํ ์ ๋ฌธ์ ๋ฅผ ์ฌ์ญ์์ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
Given
๋จ๊ณ ์ ์์๋table
์ธ์๊ฐ ์์ง๋ง ๊ธฐ๋ฅ ํ์ผ์๋ ํ ์ด๋ธ์ด ์์ต๋๋ค. Cucumber-js๋ ๋จ๊ณ ์ ์์ ์ธ์ ์๋ฅผ ๊ธฐ๋ฐ์ผ๋กcallback
์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธํฉ๋๋ค. ์ซ์๊ฐ ์ ๋ฌ๋ ์ธ์ ์๋ณด๋ค ํ๋ ๋ ๋ง์ ๊ฒฝ์ฐ ์ฝ๋ฐฑ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. ํ๋ผ๋ฏธ์ค๋ ๋ฐํํ๋ฏ๋ก ํ๋ผ๋ฏธ์ค ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธํฉ๋๋ค. ํ ๋ฒ์ ํ๋์ ์ธํฐํ์ด์ค๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.๋จ๊ณ ์ ์์ X๊ฐ์ ์ธ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ฝ๋ฐฑ ์ธํฐํ์ด์ค๊ฐ ๊ฐ์ ๋๋ค๋ ์ฌ์ค์ ๋ํ ๋ด์ฉ์ ํฌํจํ๋๋ก ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ ๋ํ ์๊ฐ์?