eugene-sea / karma-cucumber-js

Karma adapter for running Cucumber.js features
10 stars 4 forks source link

No example of invoking a browser #2

Closed robkinyon closed 8 years ago

robkinyon commented 8 years ago

The standard "Hello World" for Cucumber scenarios is visiting Google and either executing a search or checking the title or whatever. This demonstrates a complete walking skeleton, including integration with Selenium/WebDriver as a browser manager.

In this case, Karma is the browser manager - it handles launching Phantom, Karma, etc. But, I'm at a loss as to how I'm supposed to drive the browser. I don't have a browser object, so I'm not sure what I'm supposed invoke.

Could you provide an example for a feature like:

Feature: Google integrity check
  As a visitor
  I want google.com to work
  So that I can search for stuff

  Scenario: Google title test
    Given I am not logged in
    When I visit google.com
    Then I should see Google in the title
eugene-sea commented 8 years ago

It may be confusing, but in Karma tests you do not drive browser. Karma tests allows you to execute test code inside browser, so you have direct access to front-end code. E.g. you could test view models (of MVVM) from front-end by accessing them directly.

This is different from driving browser. Driving browser is usually used for end to end tests. In those tests you do not have access to view models of application, you only could simulate user input and query DOM. For such tests you do not need Karma, just plain cucumber.js is enough.

robkinyon commented 8 years ago

My intention here was to use Karma as a browser manager, similar to how Selenium and WebDriver function. I really like Karma for unit tests and was hoping to keep using it for E2E tests, reducing the number of different tools a single project needs to work with.

From your response, it appears that there is no intention of allowing the test to drive the browser similar to how Selenium and WebDriver function. Is that true?

eugene-sea commented 8 years ago

Yes, it is true. Karma tests are executed inside browser but to drive browser you need to be outside of browser.

JimLynchCodes commented 8 years ago

@robkinyon If you want to acceptance tests with step definitions that are implemented with Selenium WebDriver for AngularJS or Angular 2 apps you should check out the project for the "cucumberized" protractor framework.

As eugene said above, this project "cucumberizes" karma, and the step definitions here are meant to be implemented by injecting your Angular objects and called their public methods.