Sharing Top Content from the Angular-sphere.

Simplify your Protractor tests using Generator functions

  • With Javascript generator functions it is possible to simplify your tests.
  • We have two page objects created that can communicate with the pages in our Protractor tests.
  • This is an example of an actual testcase with the use of promise chaining:

    As you can see, the testcode is much easier to understand when the generator method is used.

  • The generator method which is defined with the syntax can be used together with the jasmine-co library.
  • Important: It is not necessary to rewrite all your tests to generators, so you can try it out on one test first.

Writing protractor tests can be quite difficult, because of all the asynchronous calls you have to deal with. Even promise-chaining does not help when your tests become longer and more complex. With Javascript generator functions it is possible to simplify your tests.

@jdriven_nl: Simplify your Protractor tests using Generator functions #AngularJS #Coding #Jasmine

Writing protractor tests can be quite difficult, because of all the asynchronous calls you have to deal with. Even promise-chaining does not help when your tests become longer and more complex. With Javascript generator functions it is possible to simplify your tests.

Example:

Let’s say we have a todo-app created in AngularJS with two pages: a page with a list of todos and a page where a user can create a todo-item. We have two page objects created that can communicate with the pages in our Protractor tests. This is an example of an actual testcase with the use of promise chaining:

As you can see, the testcode is much easier to understand when the generator method is used.

How does it work?

syntax can be used together with the jasmine-co library.

jasmine-co wraps all methods and waits for each yield statement to be resolved before continuing to the next yield statement, even if this yield statement is resolved asynchronously.

3. Start rewriting your tests incremently. Important: It is not necessary to rewrite all your tests to generators, so you can try it out on one test first.

Simplify your Protractor tests using Generator functions

Comments are closed, but trackbacks and pingbacks are open.