Skip to content

Commit 0588837

Browse files
VinayKumar VVSVinayKumar VVS
authored andcommitted
Created the Sample Selenium Python Cucumber Framework
0 parents  commit 0588837

16 files changed

+275
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output/

ReadMe.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Sample Python Selenium Cucumber Framework
2+
3+
The tech stack used in this project are:
4+
1. **Python** as the programming language for writing test code
5+
2. **Cucumber** as the framework
6+
3. **PIP3** as the build tool
7+
4. **VSCode** as the preferred IDE for writing java code.
8+
9+
#### Getting Started
10+
Setup your machine.
11+
1. Python > 3.7
12+
2. Install VSCode & open the repo
13+
3. On Terminal, navigate to repo and run following commands
14+
a. Create Virtual Env ```python3 -m venv behavex-env```
15+
b. Activate Virtual Env ```source behavex-env/bin/activate```
16+
c. Install Packages ```pip3 install -r requirements.txt```
17+
18+
#### Running tests
19+
* Run tests in Sequence: ```browser=chrome behavex```
20+
* Run tests in Parallel: ```browser=chrome behavex --parallel-processes 5 --tags @test```
21+
22+
#### Report
23+
* Report will be found here: ```/output/report.html```
24+
---

environment.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from utils.helper import *
2+
3+
def before_all(context):
4+
context.driver = None
5+
6+
def before_scenario(context, scenario):
7+
context.driver = create_driver()
8+
9+
def after_scenario(context, scenario):
10+
if context.driver:
11+
context.driver.quit()
12+
context.driver = None

features/TestA.feature

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Feature: Heroku - FormAuthentication Cases
2+
3+
@test
4+
Scenario: Success Login FormAuthentication Case
5+
Given user navigates to HerokuMainPage
6+
When user on HerokuMainPage clicks on Form Authentication
7+
When user on FormAuthenticationLoginPage enter username as "tomsmith" and password as "SuperSecretPassword!"
8+
When user on FormAuthenticationLoginPage clicks on login
9+
Then user on FormAuthenticationSuccessPage verifies this message "Secure Area"
10+
When user on FormAuthenticationSuccessPage clicks on logout
11+
Then user on FormAuthenticationLoginPage verifies this message "Login Page"
12+
13+
@test
14+
Scenario: Validate Error Message When Invalid UserName is Passed
15+
Given user navigates to HerokuMainPage
16+
When user on HerokuMainPage clicks on Form Authentication
17+
When user on FormAuthenticationLoginPage enter username as "admin" and password as "SuperSecretPassword!"
18+
When user on FormAuthenticationLoginPage clicks on login
19+
Then user on FormAuthenticationLoginPage verifies the error message as "Your username is invalid!"
20+
21+
@test
22+
Scenario: Validate Error Message When Invalid Password is Passed
23+
Given user navigates to HerokuMainPage
24+
When user on HerokuMainPage clicks on Form Authentication
25+
When user on FormAuthenticationLoginPage enter username as "tomsmith" and password as "admin"
26+
When user on FormAuthenticationLoginPage clicks on login
27+
Then user on FormAuthenticationLoginPage verifies the error message as "Your password is invalid!"

features/TestB.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Heroku - Drag And Drop Cases
2+
3+
@test
4+
Scenario: Drag A on Top of B
5+
Given user navigates to HerokuMainPage
6+
When user on HerokuMainPage clicks on DragAndDrop
7+
When user on DragAndDropPage drags "A" on top of "B"
8+
Then user on DragAndDropPage verifies the first block text as "B" and second block text as "A"
9+
10+
@test
11+
Scenario: Drag B on Top of A
12+
Given user navigates to HerokuMainPage
13+
When user on HerokuMainPage clicks on DragAndDrop
14+
When user on DragAndDropPage drags "B" on top of "A"
15+
Then user on DragAndDropPage verifies the first block text as "B" and second block text as "A"

pages/BasePage.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from selenium.webdriver.support.ui import WebDriverWait
2+
from selenium.webdriver.support import expected_conditions as EC
3+
4+
class BasePage:
5+
6+
def __init__(self, driver):
7+
self.driver = driver
8+
self.time_to_wait = 30
9+
10+
def click_on(self, by_locator):
11+
WebDriverWait(self.driver, self.time_to_wait).until(EC.visibility_of_element_located(by_locator)).click()
12+
13+
def enter_text(self, by_locator, text):
14+
WebDriverWait(self.driver, self.time_to_wait).until(EC.visibility_of_element_located(by_locator)).send_keys(text)
15+
16+
def get_element_text(self, by_locator):
17+
return WebDriverWait(self.driver, self.time_to_wait).until(EC.visibility_of_element_located(by_locator)).text
18+
19+
def get_element(self, by_locator):
20+
return WebDriverWait(self.driver, self.time_to_wait).until(EC.visibility_of_element_located(by_locator))

pages/DragAndDropPage.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pages.BasePage import BasePage
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.common.action_chains import ActionChains
4+
import time
5+
6+
class DragAndDropPage(BasePage):
7+
8+
A_BLOCK = (By.CSS_SELECTOR, "[id='column-a']")
9+
B_BLOCK = (By.CSS_SELECTOR, "[id='column-b']")
10+
11+
def __init__(self, driver):
12+
super().__init__(driver)
13+
self.driver = driver
14+
15+
def drag_and_drop_action(self, src, dest):
16+
src_locator = self.A_BLOCK if src == 'A' else self.B_BLOCK
17+
dest_locator = self.B_BLOCK if dest == 'B' else self.A_BLOCK
18+
19+
action_chains = ActionChains(self.driver)
20+
action_chains.drag_and_drop(self.get_element(src_locator), self.get_element(dest_locator)).perform()
21+
time.sleep(2)
22+
23+
def verify_src_and_dest_text(self, srcText, destText):
24+
expected_a_block_txt = self.get_element_text(self.A_BLOCK)
25+
expected_b_block_txt = self.get_element_text(self.B_BLOCK)
26+
assert srcText == expected_a_block_txt, f"Expected: {srcText}, Actual: {expected_a_block_txt}"
27+
assert destText == expected_b_block_txt, f"Expected: {destText}, Actual: {expected_b_block_txt}"

pages/FormAuthenticationLoginPage.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from pages.BasePage import BasePage
2+
from selenium.webdriver.common.by import By
3+
import time
4+
5+
class FormAuthenticationLoginPage(BasePage):
6+
7+
USERNAME_TXT = (By.CSS_SELECTOR, "[id='username']")
8+
PASSWORD_TXT = (By.CSS_SELECTOR, "[id='password']")
9+
LOGIN_BTN = (By.CSS_SELECTOR, "[type='submit']")
10+
LOGIN_SUCCESS_TXT = (By.CSS_SELECTOR, "[id='content'] h2")
11+
ERROR_TXT = (By.CSS_SELECTOR, "[id='flash']")
12+
13+
def __init__(self, driver):
14+
super().__init__(driver)
15+
self.driver = driver
16+
17+
def fill_username_and_password(self, username, password):
18+
self.enter_text(self.USERNAME_TXT, username)
19+
self.enter_text(self.PASSWORD_TXT, password)
20+
21+
def click_on_login(self):
22+
self.click_on(self.LOGIN_BTN)
23+
24+
def verify_login_text(self, text_verify):
25+
actual_text = self.get_element_text(self.LOGIN_SUCCESS_TXT)
26+
assert actual_text == text_verify
27+
28+
def verify_error_text(self, error_message):
29+
time.sleep(2)
30+
actual_text = self.get_element_text(self.ERROR_TXT)
31+
assert error_message in actual_text

pages/FormAuthenticationSucessPage.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pages.BasePage import BasePage
2+
from selenium.webdriver.common.by import By
3+
4+
class FormAuthenticationSuccessPage(BasePage):
5+
SUCCESS_TEXT = (By.CSS_SELECTOR, "[class='example'] h2")
6+
LOGOUT_BTN = (By.CSS_SELECTOR, "[href='/logout']")
7+
8+
def __init__(self, driver):
9+
super().__init__(driver)
10+
self.driver = driver
11+
12+
def verify_success_text(self, text_verify):
13+
actual_text = self.get_element_text(self.SUCCESS_TEXT)
14+
assert actual_text == text_verify
15+
16+
def click_on_logout(self):
17+
self.click_on(self.LOGOUT_BTN)

pages/HerokuMainPage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pages.BasePage import BasePage
2+
from selenium.webdriver.common.by import By
3+
4+
class HerokuMainPage(BasePage):
5+
6+
FORM_AUTHENTICATION = (By.XPATH, "//*[text()='Form Authentication']")
7+
DRAG_AND_DROP = (By.XPATH, "//*[text()='Drag and Drop']")
8+
9+
def __init__(self, driver):
10+
super().__init__(driver)
11+
self.driver = driver
12+
13+
def navigate_heroku_url(self):
14+
self.driver.get("https://the-internet.herokuapp.com/")
15+
16+
def click_on_form_authentication(self):
17+
self.click_on(self.FORM_AUTHENTICATION)
18+
19+
def click_on_drag_and_drop(self):
20+
self.click_on(self.DRAG_AND_DROP)
21+
22+

0 commit comments

Comments
 (0)