8000 Added pages and page models · ciguler/testing-python-apps@f196ab2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f196ab2

Browse files
committed
Added pages and page models
1 parent 1c09997 commit f196ab2

File tree

12 files changed

+97
-37
lines changed

12 files changed

+97
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
Feature: Test navigation between pages
2-
Make sure homepage can go to blog, and
3-
blog can go to homepage
4-
5-
Scenario: Homepage can go to Blog
6-
Given I am on the homepage
7-
When I click on the link with id "blog-link"
8-
Then I am on the blog page
9-
10-
Scenario: Blog page can go to homepage
11-
Given I am on the blog page
12-
When I click on the link with id "home-link"
13-
Then I am on the homepage
14-
1+
Feature: Test that pages have correct content
152
Scenario: Blog page has an appropriate title
163
Given I am on the blog page
174
Then There is a title shown on the page
@@ -34,4 +21,4 @@ Feature: Test navigation between pages
3421
And I press the submit button
3522
Then I am on the blog page
3623
Given I wait for the posts to load
37-
Then I can see there is a post with title "Test Post" in the posts section
24+
Then I can see there is a post with title "Test Post" in the posts section
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: Test navigation between pages
2+
Make sure homepage can go to blog, and
3+
blog can go to homepage
4+
5+
Scenario: Homepage can go to Blog
6+
Given I am on the homepage
7+
When I click on the link with id "blog-link"
8+
Then I am on the blog page
9+
10+
Scenario: Blog page can go to homepage
11+
Given I am on the blog page
12+
When I click on the link with id "home-link"
13+
Then I am on the homepage
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
class BaseLocators:
2-
pass
1+
from selenium.webdriver.common.by import By
2+
3+
4+
class BasePageLocators:
5+
TITLE = By.TAG_NAME, 'h1'
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
from selenium.webdriver.common.by import By
2+
3+
14
class BlogPageLocators:
2-
pass
5+
POSTS_SECTION = By.ID, 'posts'
6+
POST = By.CLASS_NAME, 'post-link'
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1+
from section10.video_code.tests.acceptance.page_model.base_page import BasePageLocators
2+
3+
14
class BasePage:
2-
pass
5+
6+
def __init__(self, driver):
7+
self.driver = driver
8+
9+
@property
10+
def url(self):
11+
return 'http://127.0.0.1'
12+
13+
def find_element(self, by, value):
14+
return self.driver.find_element(by, value)
15+
16+
@property
17+
def title(self):
18+
return self.find_element(*BasePageLocators.TITLE)
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
from section10.video_code.tests.acceptance.page_model.blog_page import BlogPageLocators
12
from section10.video_code.tests.acceptance.pages.base_page import BasePage
23

34

45
class BlogPage(BasePage):
5-
pass
6+
@property
7+
def url(self):
8+
return super(BlogPage, self).url + '/blog'
9+
10+
@property
11+
def posts_section(self):
12+
return self.driver.find_element(*BlogPageLocators.POSTS_SECTION)
13+
14+
@property
15+
def posts(self):
16+
return self.driver.find_elements(*BlogPageLocators.POST)

section10/video_code/tests/acceptance/pages/home_page.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33

44
class HomePage(BasePage):
5-
pass
5+
@property
6+
def url(self):
7+
return super(HomePage, self).url + '/'

section10/video_code/tests/acceptance/pages/new_post_page.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33

44
class NewPostPage(BasePage):
5-
pass
5+
@property
6+
def url(self):
7+
return super(NewPostPage, self).url + '/post'

section10/video_code/tests/acceptance/pages/post_page.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22

33

44
class PostPage(BasePage):
5-
pass
5+
6+
def __init__(self, driver, post_title):
7+
super(PostPage, self).__init__(driver)
8+
self.post_title = post_title
9+
10+
@property
11+
def url(self):
12+
return super(PostPage, self).url + '/post/' + self.post_title
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
from behave import *
2-
from selenium.webdriver.common.by import By
2+
3+
from section10.video_code.tests.acceptance.pages.base_page import BasePage
4+
from section10.video_code.tests.acceptance.pages.blog_page import BlogPage
35

46
use_step_matcher('re')
57

68

79
@then('There is a title shown on the page')
810
def step_impl(context):
9-
tag = context.browser.find_element(By.TAG_NAME, 'h1')
11+
page = BasePage(context.browser)
12+
tag = page.title
1013
assert tag is not None
1114
assert tag.is_displayed()
1215

1316

1417
@then('The title tag has content "(.*)"')
1518
def step_impl(context, content):
16-
tag = context.browser.find_element(By.TAG_NAME, 'h1')
19+
page = BasePage(context.browser)
20+
tag = page.title
1721
assert tag.text == content
1822

1923

2024
@then('I can see there is a posts section on the page')
2125
def step_impl(context):
22-
tag = context.browser.find_element_by_id('posts')
26+
page = BlogPage(context.browser)
27+
tag = page.posts_section
2328

2429
assert tag.is_displayed()
2530

2631

2732
@then('I can see there is a post with title "(.*)" in the posts section')
2833
def step_impl(context, title):
29-
tags = context.browser.find_elements(By.CLASS_NAME, 'post-link')
34+
page = BlogPage(context.browser)
35+
tags = page.posts
3036

3137
posts_with_title = [post for post in tags if post.text == title]
3238

3339
assert len(posts_with_title) > 0
40+
# assert posts_with_title[0].is_displayed()
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
from behave import *
22
from selenium import webdriver
33

4-
use_step_matcher('re')
4+
from section10.video_code.tests.acceptance.pages.base_page import BasePage
5+
from section10.video_code.tests.acceptance.pages.blog_page import BlogPage
6+
from section10.video_code.tests.acceptance.pages.new_post_page import NewPostPage
57

6-
BASE_URL = 'http://127.0.0.1:5000/'
8+
use_step_matcher('re')
79

810

911
@given('I am on the homepage')
1012
def step_impl(context):
1113
context.browser = webdriver.Chrome()
12-
context.browser.get(BASE_URL)
14+
page = BasePage(context.browser)
15+
context.browser.get(page.url)
1316

1417

1518
@given('I am on the blog page')
1619
def step_impl(context):
1720
context.browser = webdriver.Chrome()
18-
context.browser.get('{}blog'.format(BASE_URL))
21+
page = BlogPage(context.browser)
22+
context.browser.get(page.url)
1923

2024

2125
@given('I am on the new post page')
2226
def step_impl(context):
2327
context.browser = webdriver.Chrome()
24-
context.browser.get('{}post'.format(BASE_URL))
28+
page = NewPostPage(context.browser)
29+
context.browser.get(page.url)
2530

2631

2732
@then('I am on the homepage')
2833
def step_impl(context):
29-
assert context.browser.current_url == BASE_URL
34+
page = BasePage(context.browser)
35+
assert context.browser.current_url == page.url
3036

3137

3238
@then('I am on the blog page')
3339
def step_impl(context):
34-
assert context.browser.current_url == '{}blog'.format(BASE_URL)
40+
page = BlogPage(context.browser)
41+
assert context.browser.current_url == page.url
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
from behave import *
2-
from selenium.webdriver.common.by import By
32
from selenium.webdriver.support.ui import WebDriverWait
43
from selenium.webdriver.support import expected_conditions
54

5+
from section10.video_code.tests.acceptance.page_model.blog_page import BlogPageLocators
6+
67
use_step_matcher('re')
78

89

910
@given('I wait for the posts to load')
1011
def step_impl(context):
1112
try:
1213
WebDriverWait(context.browser, 5).until(
13-
expected_conditions.visibility_of_element_located((By.ID, 'posts'))
14+
expected_conditions.visibility_of_element_located(BlogPageLocators.POSTS_SECTION)
1415
)
1516
except:
1617
raise Exception()

0 commit comments

Comments
 (0)
0