Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce CustomActions feature (closes #1535) #7393

Merged
merged 15 commits into from
Dec 14, 2022

Conversation

Artem-Babich
Copy link
Contributor

@Artem-Babich Artem-Babich commented Nov 23, 2022

Purpose

In some cases, you need to create custom actions that contain multiple default actions or other custom actions.

Approach

Provide the ability to describe and register custom actions in a JS configuration file. Create a TestController.customActions property containing these actions. If the user function returns a value, the result of calling the user action will be that value. If the function does not return a value, the result will be a TestController object, which you can chain further.

API

Define Custom Actions

// JS Configuration file

module.exports = {
    customActions: {
        async makeSomething (selector) {
           await this.click(selector);
        },
        async getSelectorValue (selector) {
         return await Selector(selector).innerText;
       },
    }
}

Use Custom Actions

test('Check span value', async t => {
    const spanValue = await t.customActions.getSelectorValue('#result');

    await t.expect(spanValue).eql('OK');
});


test('Click the button and check span value', async t => {
    const spanValue = await t.customActions.makeSomething()
                             .customActions.getSelectorValue('#result');

    await t.expect(spanValue).eql('OK');
});

Reporter Changes (For Dashboard team):

  • runCustomAction is a command that fires reportTestActionStart before any inner action starts and fires reportTestActionDone after the latest inner action fineshed.
  • you can identify each custom action run using command.actionId property.
  • in the case of concurrency mode you can also use testRunId.
  • you can also access the result of the runCustomAction command(the value returned by the custom action) in the reportTestActionDone function using command.actionResult property.

An example of reporter:

const customActionsStack = {}
const shouldReportInnerActions = false;

function isCustomAction (name /*or type */) {
   return name ==='runCustomAction';
   // or return type === 'run-custom-action';
}

{
  reportTestActionStart: (actionName, { command, testRunId }) => {
     if(isCustomAction(actionName /* or command.type */ ) ) {
        const { actionId, name } = command;
        customActionsStack[testRunId].push({ actionId, name }) ;
     }
  },
  reportTestActionDone:  (name, { command, testRunId }) => {
     if( isCustomAction(actionName /* or command.type */ ) ) {
        customActionsStack[testRunId].pop();
  
        const { actionResult, actionId, name } = command;
        // Do something with actionResult
        return;
     }
  
     if (!shouldReportInnerActions && customActionsStack[testRunId].length) {
        // Do not report action
     } else {
        // Report action
     }   
  }
}

References

Closes #1535

Pre-Merge TODO

  • Write tests for your proposed changes
  • Make sure that existing tests do not fail
  • Make sure that the documentation link is correct in the Error template

@Artem-Babich Artem-Babich temporarily deployed to CI November 23, 2022 05:22 Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI November 23, 2022 05:24 Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI November 24, 2022 05:54 Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI November 24, 2022 06:14 Inactive
@AndreyBelym AndreyBelym changed the title Introduce CustomActions feature Introduce CustomActions feature (closes #1535) Nov 30, 2022
@miherlosev miherlosev self-requested a review December 5, 2022 04:39
src/api/test-controller/add-errors.ts Outdated Show resolved Hide resolved
src/api/wrap-custom-action.ts Show resolved Hide resolved
src/errors/runtime/templates.js Outdated Show resolved Hide resolved
src/errors/runtime/templates.js Outdated Show resolved Hide resolved
test/server/runner-test.js Show resolved Hide resolved
@Artem-Babich Artem-Babich temporarily deployed to CI December 8, 2022 10:37 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 8, 2022 10:54 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 8, 2022 13:04 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 9, 2022 07:39 — with GitHub Actions Inactive
src/reporter/command/command-formatter.ts Outdated Show resolved Hide resolved
src/errors/runtime/templates.js Outdated Show resolved Hide resolved
src/reporter/command/command-formatter.ts Outdated Show resolved Hide resolved
@Artem-Babich Artem-Babich temporarily deployed to CI December 10, 2022 09:50 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 10, 2022 10:03 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 10, 2022 11:49 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 12, 2022 07:15 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich temporarily deployed to CI December 12, 2022 09:52 — with GitHub Actions Inactive
@Artem-Babich Artem-Babich merged commit f3dc5d2 into DevExpress:master Dec 14, 2022
@Artem-Babich Artem-Babich deleted the BabichA-dev-1 branch December 14, 2022 07:45
@github-actions
Copy link

Release v2.1.1-alpha.3 addresses this.

miherlosev pushed a commit that referenced this pull request Dec 27, 2022
## Purpose
TestController.customActions property doesn't have types definitions. 

## References
#7393

## Pre-Merge TODO
- [ ] Make sure that existing tests do not fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide the capability to add custom actions to the test controller
3 participants