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

Is it possible to translate actor provided steps? #184

Closed
abner opened this issue Aug 3, 2016 · 3 comments
Closed

Is it possible to translate actor provided steps? #184

abner opened this issue Aug 3, 2016 · 3 comments

Comments

@abner
Copy link
Contributor

abner commented Aug 3, 2016

Threre is a channel where i would ask few questions about codecept to you?

I work as a System Analyst in the major Governament IT Company in Brasil, called SERPRO. Actually i'm working as a consultant in web frontend technologies (at this time AngularJS, Angular 2 [both Javascript and Typescript]) and yesterday casually i found the codecept project and quickly tried it and liked so much.

I would like to use the navigation helper methods in Brazillian Portuguese, so this tests scenarios will serve as our stories documentation too.

I just came out with this setup:

1 - In the codecept.json file i include a step file like this:

"include": {
    "Eu": "./e2e/steps/steps_file.js"
  },

Eu is I in portuguese

And in the steps_file i created proxy methods in portuguese just calling the corresponding methods:

 estouNaPagina: function(url) {
      return this.amOnPage(url);
 },

vejo: function(text) {
   return this.see(text);
},

naoEstouEmAplicacaoAngular: function() {
    return this.amOutsideAngularApp();
 }

There is some path into the codeceptjs to achieve the translation of all the helpers methods codecept already provides?

I was wondering if an approach like define a mapping json and run some generator to build the steps would be a good way of doing this.

What do you think?

@DavertMik
Copy link
Contributor

DavertMik commented Aug 3, 2016

Sure! Actually I love the idea. Probably it won't be as meaningful as Cucumber scenarios (it is still JavaScript, anyway), but this mapping looks like a really good idea. To be honset, I had a plan to integrate Cucumber scenarios for high-level business expectations, they could also be used for translations.

I think this can be implemented patching lib/actor and lib/step files.

Step should be able to make different properties for helper method and step name itself:

constructor(helper, name) {
    this.name = name;
    this.helperMethod = name;
}
// inside run() we change to helperMethod
result = this.helper[this.helperMethod].apply(this.helper, this.args);

then we can easily change step name:

step.name = 'myNewName'; // this won't affect test exectution

as for lib/actor you can adjust it to change step names by mappings you provide somewhere:

module.exports = function (obj) {
  obj = obj || {};

  let helpers = container.helpers();
  Object.keys(helpers)
    .map(function (key) { return helpers[key];})
    .forEach((helper) => {
      methodsOfObject(helper, 'Helper')
      .filter((method) => {
        return method !== 'constructor' && method[0] !== '_';})
      .forEach((action) => {
        obj[action] = function () {
          let args = arguments;
          recorder.addStep(let step = new Step(helper, action), args);
          // here we change the step name:
          step.name = corresponding.mapping.name; // taken from some config....
          return recorder.promise();
        };
      });
    });

  return obj;
};

If you have an idea how to pass and where to store such mappings (probably somwhere in codecept.json), you can update the code in a way I proposed and submit a pull request.

@abner
Copy link
Contributor Author

abner commented Aug 5, 2016

just submitted a pull request for this #189

@DavertMik
Copy link
Contributor

Implemented in #189
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants