TestCafe: Generate Tests using Data from the Client?











up vote
0
down vote

favorite












Using TestCafe [1], I would like to do the following:




  1. Navigate to a URL.

  2. Execute Client-Side JavaScript to retrieve a list of other URLs.

  3. Generate a test for each URL.

  4. Execute the tests concurrently.


Working example which uses a single Test and executes serially



The reduced test case below works but is not quite what I need, it does the following:




  1. Execute a test.

  2. Navigate to a URL in the "before" hook of the test.

  3. Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.

  4. Run the assertions for each URL serially in the body of the test.


My test file run through TestCafe contains this:



import { ClientFunction, Selector } from 'testcafe';

const getSiteMapFromClientSide = ClientFunction(
() =>
new Promise(resolve => {
// this example looks like it could be synchronous, or that the data could
// be defined in the test but this data comes from an async source which
// is only reachable client side.
resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
})
);

fixture('Storybook').page('https://localhost:6007');

const modalError = Selector('#error-message');

test.before(async t => {
t.ctx.siteMap = await getSiteMapFromClientSide();
})('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
// assert we have URLs or we'll have a passing suite that looped over nothing
await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
// assert each story has no full screen error message
await Promise.all(
t.ctx.allStories.map(async url => {
await t
.navigateTo(url)
.expect(modalError.exists && modalError.visible)
.notOk(`Full Screen Error found at ${url}`);
})
);
});


Context



In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
of require('@storybook/react').getStorybook(), which is only available in the Storybook Client Application at runtime.
I've left these details out of the reduced test case as they're nothing to with TestCafe.



[1] http://devexpress.github.io/testcafe
[2] https://storybook.js.org










share|improve this question




























    up vote
    0
    down vote

    favorite












    Using TestCafe [1], I would like to do the following:




    1. Navigate to a URL.

    2. Execute Client-Side JavaScript to retrieve a list of other URLs.

    3. Generate a test for each URL.

    4. Execute the tests concurrently.


    Working example which uses a single Test and executes serially



    The reduced test case below works but is not quite what I need, it does the following:




    1. Execute a test.

    2. Navigate to a URL in the "before" hook of the test.

    3. Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.

    4. Run the assertions for each URL serially in the body of the test.


    My test file run through TestCafe contains this:



    import { ClientFunction, Selector } from 'testcafe';

    const getSiteMapFromClientSide = ClientFunction(
    () =>
    new Promise(resolve => {
    // this example looks like it could be synchronous, or that the data could
    // be defined in the test but this data comes from an async source which
    // is only reachable client side.
    resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
    })
    );

    fixture('Storybook').page('https://localhost:6007');

    const modalError = Selector('#error-message');

    test.before(async t => {
    t.ctx.siteMap = await getSiteMapFromClientSide();
    })('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
    // assert we have URLs or we'll have a passing suite that looped over nothing
    await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
    // assert each story has no full screen error message
    await Promise.all(
    t.ctx.allStories.map(async url => {
    await t
    .navigateTo(url)
    .expect(modalError.exists && modalError.visible)
    .notOk(`Full Screen Error found at ${url}`);
    })
    );
    });


    Context



    In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
    of require('@storybook/react').getStorybook(), which is only available in the Storybook Client Application at runtime.
    I've left these details out of the reduced test case as they're nothing to with TestCafe.



    [1] http://devexpress.github.io/testcafe
    [2] https://storybook.js.org










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Using TestCafe [1], I would like to do the following:




      1. Navigate to a URL.

      2. Execute Client-Side JavaScript to retrieve a list of other URLs.

      3. Generate a test for each URL.

      4. Execute the tests concurrently.


      Working example which uses a single Test and executes serially



      The reduced test case below works but is not quite what I need, it does the following:




      1. Execute a test.

      2. Navigate to a URL in the "before" hook of the test.

      3. Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.

      4. Run the assertions for each URL serially in the body of the test.


      My test file run through TestCafe contains this:



      import { ClientFunction, Selector } from 'testcafe';

      const getSiteMapFromClientSide = ClientFunction(
      () =>
      new Promise(resolve => {
      // this example looks like it could be synchronous, or that the data could
      // be defined in the test but this data comes from an async source which
      // is only reachable client side.
      resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
      })
      );

      fixture('Storybook').page('https://localhost:6007');

      const modalError = Selector('#error-message');

      test.before(async t => {
      t.ctx.siteMap = await getSiteMapFromClientSide();
      })('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
      // assert we have URLs or we'll have a passing suite that looped over nothing
      await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
      // assert each story has no full screen error message
      await Promise.all(
      t.ctx.allStories.map(async url => {
      await t
      .navigateTo(url)
      .expect(modalError.exists && modalError.visible)
      .notOk(`Full Screen Error found at ${url}`);
      })
      );
      });


      Context



      In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
      of require('@storybook/react').getStorybook(), which is only available in the Storybook Client Application at runtime.
      I've left these details out of the reduced test case as they're nothing to with TestCafe.



      [1] http://devexpress.github.io/testcafe
      [2] https://storybook.js.org










      share|improve this question















      Using TestCafe [1], I would like to do the following:




      1. Navigate to a URL.

      2. Execute Client-Side JavaScript to retrieve a list of other URLs.

      3. Generate a test for each URL.

      4. Execute the tests concurrently.


      Working example which uses a single Test and executes serially



      The reduced test case below works but is not quite what I need, it does the following:




      1. Execute a test.

      2. Navigate to a URL in the "before" hook of the test.

      3. Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.

      4. Run the assertions for each URL serially in the body of the test.


      My test file run through TestCafe contains this:



      import { ClientFunction, Selector } from 'testcafe';

      const getSiteMapFromClientSide = ClientFunction(
      () =>
      new Promise(resolve => {
      // this example looks like it could be synchronous, or that the data could
      // be defined in the test but this data comes from an async source which
      // is only reachable client side.
      resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
      })
      );

      fixture('Storybook').page('https://localhost:6007');

      const modalError = Selector('#error-message');

      test.before(async t => {
      t.ctx.siteMap = await getSiteMapFromClientSide();
      })('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
      // assert we have URLs or we'll have a passing suite that looped over nothing
      await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
      // assert each story has no full screen error message
      await Promise.all(
      t.ctx.allStories.map(async url => {
      await t
      .navigateTo(url)
      .expect(modalError.exists && modalError.visible)
      .notOk(`Full Screen Error found at ${url}`);
      })
      );
      });


      Context



      In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
      of require('@storybook/react').getStorybook(), which is only available in the Storybook Client Application at runtime.
      I've left these details out of the reduced test case as they're nothing to with TestCafe.



      [1] http://devexpress.github.io/testcafe
      [2] https://storybook.js.org







      automated-tests e2e-testing testcafe storybook






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 11:17









      Alex Skorkin

      2,0121430




      2,0121430










      asked Nov 8 at 9:59









      Jamie Mason

      2,27411631




      2,27411631
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          I think it's better to divide your task into two parts.
          First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
          Then start a new TestCafe task with the concurrency option and set the src param to your second test file.
          The best way to do it is to use the createTestCafe function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205332%2ftestcafe-generate-tests-using-data-from-the-client%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            I think it's better to divide your task into two parts.
            First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
            Then start a new TestCafe task with the concurrency option and set the src param to your second test file.
            The best way to do it is to use the createTestCafe function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html






            share|improve this answer

























              up vote
              1
              down vote













              I think it's better to divide your task into two parts.
              First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
              Then start a new TestCafe task with the concurrency option and set the src param to your second test file.
              The best way to do it is to use the createTestCafe function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                I think it's better to divide your task into two parts.
                First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
                Then start a new TestCafe task with the concurrency option and set the src param to your second test file.
                The best way to do it is to use the createTestCafe function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html






                share|improve this answer












                I think it's better to divide your task into two parts.
                First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
                Then start a new TestCafe task with the concurrency option and set the src param to your second test file.
                The best way to do it is to use the createTestCafe function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                Alex Kamaev

                2664




                2664






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205332%2ftestcafe-generate-tests-using-data-from-the-client%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Schultheiß

                    Liste der Kulturdenkmale in Wilsdruff

                    Android Play Services Check