Cucumber-js: ์˜ค๋ฅ˜: ํ•จ์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ ๋น„๋™๊ธฐ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค: ์ฝœ๋ฐฑ ๋ฐ ์•ฝ์†

์— ๋งŒ๋“  2017๋…„ 07์›” 03์ผ  ยท  7์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: cucumber/cucumber-js

์—ฌ๋Ÿฌ๋ถ„, ์•ˆ๋…•ํ•˜์„ธ์š”,
๋‹จ๊ณ„ ์ •์˜์—์„œ ๋น„๋™๊ธฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
๋‚ด ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์˜ 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๊ฐœ์˜ ์ธ์ˆ˜๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฝœ๋ฐฑ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๊ฐ€์ •๋œ๋‹ค๋Š” ์‚ฌ์‹ค์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ํฌํ•จํ•˜๋„๋ก ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ์ƒ๊ฐ์€?

๋ชจ๋“  7 ๋Œ“๊ธ€

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๋กœ ๋ฌธ์ œ๋ฅผ ๋‹ซ๋Š” ๊ฒƒ์€ ๊ธฐ๋Šฅ ํŒŒ์ผ์—์„œ ๋‚ด ์ž์‹ ์˜ ์ฝ”๋”ฉ ์˜ค๋ฅ˜๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๋‹คํ–‰์ž…๋‹ˆ๋‹ค. ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€ ์—…๋ฐ์ดํŠธ์— ๋Œ€ํ•œ ๋ณ„๋„์˜ ๋ฌธ์ œ๋ฅผ ์—ด์–ด ํ–ฅํ›„ ๋” ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์ด ์Šค๋ ˆ๋“œ๋Š” ๋‹ซํžŒ ํ›„ ์ตœ๊ทผ ํ™œ๋™์ด ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ž๋™์œผ๋กœ ์ž ๊ฒผ์Šต๋‹ˆ๋‹ค. ๊ด€๋ จ ๋ฒ„๊ทธ์— ๋Œ€ํ•œ ์ƒˆ ๋ฌธ์ œ๋ฅผ ์—ฌ์‹ญ์‹œ์˜ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰