Skip to content

Commit 6d01bf1

Browse files
committed
Added project source code
1 parent 1f05b73 commit 6d01bf1

27 files changed

+355
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# agile-development
1+
# Agile Software Development using TDD/BDD

clean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
find . -name "*.pyc" | xargs rm -f

python/bdd/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Setup BDD Test Environment
2+
- Install `pexpect` using `python-pip`: `sudo pip install pexpect`
3+
- Install `behave` using `python-pip`: `sudo pip install behave`
4+
5+
## Run all tests
6+
- Change directory to `python/bdd/features/`
7+
- Run tests: `behave`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Development environment provision
2+
As DevOps
3+
I want to verify all the expected dependencies properly installed
4+
So that development environments for Developers are spun up in a consistent way
5+
6+
Scenario Outline: Assert correct dev and test dependencies are installed properly
7+
Given a Ubuntu development machine
8+
When I execute "<command>"
9+
Then I should see "<expected>"
10+
11+
Examples:
12+
| command | expected |
13+
| cat /etc/os-release | Ubuntu 14.04 |
14+
| python --version | Python 2.7 |
15+
| nosetests --version | nosetests version 1.3 |
16+
| coverage --version | Coverage.py, version 4.4 |
17+
| phantomjs --version | 1.9 |
18+
| behave --version | behave 1.2 |

python/bdd/features/nose.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: nosetests
2+
3+
Scenario: nosetests runs all tests
4+
Given nose is installed
5+
When I execute "nosetests"
6+
Then I should see "OK"

python/bdd/features/search.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Search
2+
3+
Scenario Outline: Assert search works
4+
Given I navigate to "<url>"
5+
When I search for "<keyword>"
6+
Then I should see "<expected>" in the page title
7+
8+
Examples:
9+
| url | keyword | expected |
10+
| http://www.google.com | Mazedur Rahman | Mazedur Rahman |

python/bdd/features/steps/steps.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from behave import *
2+
import subprocess
3+
import pexpect
4+
5+
import unittest
6+
from selenium import webdriver
7+
from selenium.common.exceptions import TimeoutException
8+
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
9+
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
10+
11+
driver = webdriver.PhantomJS()
12+
13+
@given(u'a Ubuntu development machine')
14+
def step_impl(context):
15+
pass
16+
17+
@given(u'nose is installed')
18+
def step_impl(context):
19+
pass
20+
21+
@given(u'coverage is installed')
22+
def step_impl(context):
23+
pass
24+
25+
@when(u'I execute "{cmd}"')
26+
def step_impl(context, cmd):
27+
out = execute(cmd)
28+
context.out = out
29+
30+
@then(u'I should see "{expected_text}"')
31+
def step_impl(context, expected_text):
32+
assert expected_text in context.out
33+
34+
def execute(cmd):
35+
output, status = pexpect.run(cmd
36+
, withexitstatus=1
37+
, timeout=600
38+
)
39+
40+
return output
41+
42+
@given(u'I navigate to "{url}"')
43+
def step_impl(context, url):
44+
driver.get(url)
45+
46+
@when(u'I search for "{keyword}"')
47+
def step_impl(context, keyword):
48+
inputElement = driver.find_element_by_name("q")
49+
inputElement.send_keys(keyword)
50+
inputElement.submit()
51+
context.driver = driver
52+
53+
@then(u'I should see "{expected_text}" in the page title')
54+
def step_impl(context, expected_text):
55+
WebDriverWait(context.driver, 10).until(EC.title_contains(expected_text))

python/selenium/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Setup Selenium Test Environment
2+
- Install `phantomjs`: `sudo apt-get install -y phantomjs`
3+
- Install Selenium WebDriver: `sudo pip install selenium`
4+
5+
## Run all tests
6+
- Change directory to `python/selenium/`
7+
- Run tests: `nosetests`
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
from selenium import webdriver
3+
from selenium.common.exceptions import TimeoutException
4+
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
5+
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
6+
7+
class TestSeleniumUsingPhantomJS(unittest.TestCase):
8+
9+
def setUp(self):
10+
self.driver = webdriver.PhantomJS()
11+
12+
def test_page_title_exists(self):
13+
self.driver.get('http://ieeexplore.ieee.org/')
14+
15+
assert "IEEE Xplore Digital Library" in self.driver.title
16+
17+
def test_google_search_works(self):
18+
# go to the google home page
19+
self.driver.get("http://www.google.com")
20+
21+
# find the element that's name attribute is q (the google search box)
22+
inputElement = self.driver.find_element_by_name("q")
23+
24+
# type in the search
25+
inputElement.send_keys("Mazedur Rahman")
26+
27+
# submit the form (although google automatically searches now without submitting)
28+
inputElement.submit()
29+
30+
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
31+
WebDriverWait(self.driver, 10).until(EC.title_contains("Mazedur Rahman"))
32+
33+
def tearDown(self):
34+
self.driver.quit()
35+
36+
if __name__ == '__main__':
37+
unittest.main()

python/tdd/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Run all tests
2+
- Change directory to the location of source and test code
3+
- Run tests: `nosetests`
4+
- Run tests with coverage report: `nosetests --with-coverage --cover-package=.`

0 commit comments

Comments
 (0)