Top Banner
User Acceptance Test with Behat Long Nguyen
16

Acceptance test with behat

Apr 10, 2017

Download

Software

Long Nguyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Acceptance test with behat

User Acceptance Test with Behat

Long Nguyen

Page 2: Acceptance test with behat
Page 3: Acceptance test with behat

Architecture

Page 4: Acceptance test with behat

Test Google ??

Page 5: Acceptance test with behat

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" },

Page 6: Acceptance test with behat

Mink Driver

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

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

Page 7: Acceptance test with behat

install selenium (HOW #1.1)

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

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

Page 8: Acceptance test with behat

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: ~

Page 9: Acceptance test with behat

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"

Page 10: Acceptance test with behat

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); }}

Page 11: Acceptance test with behat

HOW #5vendor/bin/behat

autoload

read feature - compare with context

Page 12: Acceptance test with behat

Hooks

Page 13: Acceptance test with behat

Hooks

Page 14: Acceptance test with behat

xpath

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

Page 15: Acceptance test with behat
Page 16: Acceptance test with behat

Reference:

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

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

Demo code:

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