16
User Acceptance Test with Behat Long Nguyen

Acceptance test with behat

Embed Size (px)

Citation preview

User Acceptance Test with Behat

Long Nguyen

Architecture

Test Google ??

HOW #1

composer.json

"require-dev": { "behat/behat": "^3.0", "behat/gherkin": "^4.4", "behat/mink-extension": "^2.1", "behat/mink-selenium2-driver": "^1.3" },

Mink Driver

https://mink.readthedocs.org/en/latest/guides/drivers.html

choose appropriate driver for appropriate kind of browser (selenium, phantomjs, etc …)

install selenium (HOW #1.1)

http://www.seleniumhq.org/download/

alias startselenium='java -jar /opt/selenium-testing/selenium-server-standalone-2.47.1.jar'

HOW #2

behat.yml

default: autoload: [ %paths.base%/test/acceptance/contexts ] suites: test_google_features: paths: [ %paths.base%/test/acceptance/features ] contexts: [ TestGoogleContext ] extensions: Behat\MinkExtension: base_url: https://google.com selenium2: ~

HOW #3

define feature

# features/TestGoogle.featureFeature: Test Google In order to search for something

Scenario: Search for how google works Given I am on "/" When I fill in "q" with "how google works" And I press "btnG" Then I wait for the next step Then I should see "How Google Works"

HOW #4

define context

<?php

use Behat\MinkExtension\Context\MinkContext;

class TestGoogleContext extends MinkContext{ /** * @Then /^I wait for the next step$/ */ public function iWaitForTheNextStep() { $this->getSession()->wait(1000); }}

HOW #5vendor/bin/behat

autoload

read feature - compare with context

Hooks

Hooks

xpath

ref: http://mink.behat.org/en/latest/guides/traversing-pages.html

Reference:

http://docs.behat.org/en/v3.0/

https://mink.readthedocs.org/en/latest/

Demo code:

https://github.com/nguyentienlong/demo-behat