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

Migrate some old PRs WIP #39

Merged
merged 12 commits into from
Oct 16, 2017
Merged
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ it is good enough to replace the existing documentation.
Please make ALL contributions to the documentation in [docs.cucumber.io](https://github.com/cucumber/docs.cucumber.io).

## Current status
We are working to add and update all of the old documentation (see below) to this repo.
We are working to add and update all of the old documentation (see below) to this repo.

All *relevant* documentation from the old documentation has been added to this project.
Some files have been deleted; this does not necessarily mean that those files should not exist,
Some files have been deleted; this does not necessarily mean that those files should not exist,
just that there was not enough info there to justify leaving them.

**This work is currently being done and has been merged to master**.
Expand Down Expand Up @@ -72,7 +72,7 @@ Open a browser:

### Modify content

Simply edit Markdown files under `content`.
Edit Markdown files under in the `content` directory.

Whenever you make a change to the content, the server will automatically rebuild the site (in a few milliseconds) and tell the browser to reload (using a WebSocket).

Expand Down
180 changes: 114 additions & 66 deletions content/cucumber/browser-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
menu: reference
renderer: Cucumber::Website::Reference
title: Browser Automation
polyglot: true
---

# Browser Automation
Expand All @@ -16,86 +17,149 @@ Automation tools such as:

## Selenium WebDriver

Let's convert the [Selenium-Webdriver by Example tutorial](http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example)
to use Cucumber.
WebDriver is designed to provide a simpler, more concise programming interface in addition to addressing some limitations in the Selenium-RC API. Selenium-WebDriver was developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded. WebDriver's goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems.

We can express the example as the following Scenario:
Let us look at an example of Cucumber using selenium-webdriver in UI testing, by converting [Selenium-Web driver by example ](http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example).

```gherkin
Scenario: Finding some cheese
Given I am on the Google search page
When I search for "Cheese!"
Then the page title should start with "cheese"
```
We can express the example as the following Scenario:

Here are the accompanying Step Definitions:

[carousel]

```ruby
# TODO! See the Java example for now.
```Gherkin
Scenario: Finding some cheese
Given I am on the Google search page
When I search for "Cheese!"
Then the page title should start with "cheese"
```

```java
package com.example;
package class.exmple;

public class ExampleSteps {
private final WebDriver driver = new FirefoxDriver();

@Given("^I am on the Google search page$")
private final WebDriver driver = new FirefoxDriver();
@Given("^I am on the Google search page$"\)
public void I_visit_google() {
driver.get("https://www.google.com");
}
driver.get("https:\\www.google.com");
}

@When("^I search for \"(.*)\"$")
public void search_for(String query) {
WebElement element = browser.findElement(By.name("q"));
// Enter something to search for
@When("^I search for \"(.*)\"$")
public void search_for(String query) {
WebElement element = browser.findElelment(By.name("q"));
//Enter Something to search for
element.sendKeys(query);
// Now submit the form. WebDriver will find the form for us from the element
//Now submit the form. WebDriver will find the form for us from the element
element.submit();
}

@Then("^the page title should start with \"(.*)\"$")
public void checkTitle() {
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese");
}
});
assertThat(driver.getTitle(), startsWith("cheese"));
// Should see: "cheese! - Google Search"
}

@Then("^ the page title should start with \"(.*)\"$")
public void checkTitle() {
//Google's search is rendered dynamically with JavaScript.
//Wait for the page to load timeout after ten seconds
new WebDriverWait(driver,'10')).untill(new ExpectedCondition<Boolean> {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase.startsWith("cheese");
//Should see: "cheese! -Google Search"
}

@After()
public void closeBrowser() {
driver.quit();
}
public void closeBrowser() {
driver.quit();
}
}
```

[/carousel]

## Watir
```ruby
require 'rubygems'
require 'selenium-webdriver'

Given("^I am on the Google search page$") do
driver = Selenium::WebDriver.for :firefox
driver.get "http:\\google.com"
end

When("^I search for "([^"]*)"$") do
element = driver.find_element(:name => "q")
element.send_keys "Cheese!"
element.submit
end

Then("^the page title should start with "([^"]*)"$") do
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.title.downcase.start_with? "cheese!" }
puts "Page title is #{driver.title}"
browser.close
end
```

## Watir Webdriver

TODO
Watir, pronounced water, is an open-source (BSD) family of Ruby libraries for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.

Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.

Watir is a family of Ruby libraries but it supports your application no matter which technology it is developed in. While Watir supports only Internet Explorer on Windows; Watir-WebDriver solves single browser testing and support Chrome, Firefox, Internet Explorer, Opera and also running in headless mode (HTMLUnit).

Now let's jump in to a sample UI testing program using Watir:

```ruby
require "rubygems"
require "rspec"
require "watir-webdriver"

describe "google.com" do
let(:browser) { @browser ||= Watir::Browser.new :firefox }
before { browser.goto "http://google.com" }
browser.text_field(:name => "q").set "watir"
browser.button.click
browser.div(:id => "resultStats").wait_until_present
browser.title.should == "watir - Google Search"
after { browser.close }
end
```

Now let us incorporate Cucumber to this simple test

```gherkin
Feature: Search In order to use Google users must be able to search for content
Scenario: Search for a term
Given I have entered "watir" into the query
When I click "search"
Then I should see some results
```

```ruby
require "watir-webdriver"
require "rspec/expectations"

Given /^I have entered "([^"]*)" into the query$/ do |term|
@browser ||= Watir::Browser.new :firefox
@browser.goto "google.com"
@browser.text_field(:name => "q").set term
end

When /^I click "([^"]*)"$/ do |button_name|
@browser.button.click
end

Then /^I should see some results$/ do
@browser.div(:id => "resultStats").wait_until_present
@browser.div(:id => "resultStats").should exist
@browser.close
end
```

## Serenity BDD

Serenity BDD is an open source reporting library that helps you write better
structured, more maintainable automated acceptance criteria. Serenity also produces
rich meaningful test reports (or "living documentation") that report not only the
test results, but also which Features have been tested.
test results, but also which Features have been tested.

A detailed tutorial on using Cucumber-JVM with Serenity can be found
[here](http://thucydides.info/docs/articles/an-introduction-to-serenity-bdd-with-cucumber.html).

The above Scenario's Step Definitions might be written for Serenity like this:

[carousel]

```ruby
# Serenity only works with Java for now.
```
Expand Down Expand Up @@ -134,13 +198,9 @@ public class SearchSteps {
}
```

[/carousel]

In this example, the `WebDriver` interaction is delegated to `PageObject` subclasses.
In this example, the `WebDriver` interaction is delegated to `PageObject` subclasses.
Serenity has built-in support for `PageObject`s, which might look like this:

[carousel]

```ruby
# Serenity only works with Java for now.
```
Expand Down Expand Up @@ -169,16 +229,12 @@ public class GoogleHomePage extends PageObject {
public class SearchResultsPage extends PageObject {}
```

[/carousel]

## Tips and Tricks

### Multiple Browsers

Cucumber can run your Scenarios with different browsers.
Simply select the browser to use based on a configuration property loaded at runtime:
Cucumber can run your Scenarios with different browsers, based on a configuration property loaded at runtime:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also provide java (and javascript?) examples?


[carousel]

```ruby
Capybara.register_driver :selenium do |app|
Expand Down Expand Up @@ -207,12 +263,8 @@ public class WebDriverFactory {
}
```

[/carousel]

Then, simply define the `browser` property when you run Cucumber:

[carousel]

```
browser=chrome cucumber
```
Expand All @@ -221,23 +273,19 @@ browser=chrome cucumber
mvn test -Dbrowser=chrome
```

[/carousel]

If you are using Serenity, simply pass the `driver` system property (no extra coding required):

[carousel]

```
mvn test -Ddriver=chrome
```

[/carousel]

### Re-using the browser window

Closing and re-opening the browser window between Scenarios will slow them down.

To reuse them, you can use the [`SharedDriver`](https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-webbit-websockets-selenium/src/test/java/cucumber/examples/java/websockets/SharedDriver.java)
To reuse them, you can use the [`SharedDriver`](https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-webbit-websockets-selenium/src/test/java/cucumber/examples/java/websockets/SharedDriver.java)
wrapper rather than calling `WebDriver` directly.

### Example Projects
Expand Down
28 changes: 14 additions & 14 deletions content/cucumber/cucumber.yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source: https://github.com/cucumber/cucumber/wiki/cucumber.yml/
title: cucumber.yml
---

You can specify commonly-used command line arguments for Cucmber in a `cucumber.yml` or `cucumber.yaml` file.
You can specify commonly-used command line arguments for Cucmber in a `cucumber.yml` or `cucumber.yaml` file.
This file must be in a `.config` subdirectory, or `config` subdirectory of your current working directory.

## Defining Profiles
Expand All @@ -18,12 +18,12 @@ This file must be in a `.config` subdirectory, or `config` subdirectory of your
bvt: --tags @bvt
```

Defining a template requires a name and then the command-line options that you
want to execute with this profile.
Defining a template requires a name and then the command-line options that you
want to execute with this profile.

The example above generates two profiles:
The example above generates two profiles:

1. `html_report`, with a list of command-line options that specify new output formats, and
1. `html_report`, with a list of command-line options that specify new output formats, and
2. `bvt`, which executes all Features and Scenarios [tagged](/cucumber/tags/) with `@bvt`.

## Executing Profiles
Expand All @@ -33,16 +33,16 @@ The example above generates two profiles:
\[user@system project] cucumber -p bvt
```

Simply use the flag `--profile` or `-p` to execute Cucumber with a profile.
You can still use other command line arguments alongside `--profile` or `-p`,
Use the flag `--profile` or `-p` to execute Cucumber with a profile.
You can still use other command line arguments alongside `--profile` or `-p`,
if desired.

```bash
\[user@system project] cucumber --profile html_report --tags ~@wip
```

Multiple profiles can even be specified together. The following executes all
Features and Scenarios tagged `@bvt`, with the specified progress and HTML
Multiple profiles can even be specified together. The following executes all
Features and Scenarios tagged `@bvt`, with the specified progress and HTML
output.

```bash
Expand All @@ -51,8 +51,8 @@ output.

## Default Profile

Chances are you’ll want to execute Cucumber with a particular profile most of the time.
The Cucumber configuration file uses a `default` profile to provide this functionality.
Chances are you’ll want to execute Cucumber with a particular profile most of the time.
The Cucumber configuration file uses a `default` profile to provide this functionality.
When you specify a `default` profile, you are telling Cucumber to use the `default` command-line options whenever you don't explicitly specify a different profile.

Using the same example, perhaps we want the `html_report` profile to be our default execution.
Expand All @@ -71,13 +71,13 @@ Using the same example, perhaps we want the `html_report` profile to be our defa
```

With this setup, Cucumber will now use both the `bvt` profile and `html_report`
profile, testing all Features and Scenarios tagged with `@bvt`, along with the
profile, testing all Features and Scenarios tagged with `@bvt`, along with the
progress output and HTML output.

## Preprocessing with ERb

The `cucumber.yml` file is preprocessed by ERb. This allows you to use Ruby code
to generate values in the `cucumber.yml` file.
The `cucumber.yml` file is preprocessed by ERb. This allows you to use Ruby code
to generate values in the `cucumber.yml` file.

So, if you have several profiles with similar values, you might do this:

Expand Down
2 changes: 0 additions & 2 deletions content/implementations/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ nav: docs
title: C++
---

# C++

The documentation is currently on [GitHub](https://github.com/cucumber/cucumber-cpp).
Loading