Skip to content

Commit

Permalink
Develop (#94)
Browse files Browse the repository at this point in the history
### To be filled by the PR creator:

* A brief description of the changes made - 

* Do we have clean latest run report (Docker or Browserstack) attached
with this PR?
  * [ ] Yes
  * [ ] No (Please explain why)

* Does the PR contain changes to any core file?
  * [ ] Yes (Needs approval from at least 1 people)
  * [ ] No

* Is it
  * [ ] New Testcase
  * [ ] Fix


### To be filled by the PR reviewer:

* [ ] Verify the attached run report passed in GitHub Actions (Docker or
Browserstack run)

* General
    * [ ] Use the best strategy to locate the elements
    * [ ] Comments wherever the code is not readable by itself
    * [ ] Use of the right data structure for the use case
    * [ ] Reuse logic/functionality as much as possible
    * [ ] Cleanup of any test data that is generated by the tests
    * [ ] No static waits
  • Loading branch information
tauqirsarwar1 authored Apr 15, 2024
2 parents 6088c30 + 58f2ad0 commit dabab93
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ allure-report/*
reports/screenshots/*
/test_data/visualtesting/test/*
/output/
/test_data/files/*
2 changes: 1 addition & 1 deletion frontend/test_project/features/api/api_tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Feature: Test HTTP methods for a REST API
Given I set the GET endpoint to '/posts' for fetching posts
When I send a GET HTTP request
# Failing the test on purpose to see the failure in the report
Then I expect the HTTP response code of 'GET' to be '2000'
Then I expect the HTTP response code of 'GET' to be '200'
And I expect the response body of 'GET' to be non-empty

@api_smoke
Expand Down
43 changes: 40 additions & 3 deletions frontend/test_project/features/api/test_feature.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from os import environ

import pytest
from main.backend.common.step_definitions.steps_common import *
from assertpy import assert_that
from openai import OpenAI

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

from main.frontend.common.step_definitions import open_base_url, maximize, page_title

logger = structlog.get_logger(__name__)
client = OpenAI(api_key=environ.get("OPEN_KEY"))


API_POST_CALL = "post_call"
DELETE_ENDPOINT = "/posts/1"
POST_ENDPOINT = "/posts"
chrome_driver = webdriver.Chrome()


@pytest.mark.nondestructive
Expand All @@ -26,7 +32,7 @@ def test_send_post_request(request, api_response_container):
test_case_name=request.node.name,
)
set_request_endpoint(request, request_name=API_POST_CALL, base_url='{%API_BASE_URL%}', endpoint=POST_ENDPOINT)
set_request_headers(request, request_name=API_POST_CALL,headers="./test_data/api/payloads/sample/headers.json")
set_request_headers(request, request_name=API_POST_CALL, headers="./test_data/api/payloads/sample/headers.json")
add_json_payload(request, request_name=API_POST_CALL, json_payload="./test_data/api/payloads/post_payload_1.json")
make_api_request(request, api_response_container, request_name=API_POST_CALL, request_type='POST')

Expand All @@ -39,6 +45,37 @@ def test_send_post_request(request, api_response_container):
)


@pytest.mark.nondestructive
@pytest.mark.automated
@pytest.mark.hrmlogin
@pytest.mark.test_name("Login into OrangeHRM system and logout")
def test_login():
logger.info(
"Scenario is started"
)
chrome_driver.get('https://lambdatest.github.io/sample-todo-app/')
chrome_driver.maximize_window()

title = chrome_driver.title
assert 'Sample page - lambdatest.com' in title

first_checkbox = chrome_driver.find_element(By.XPATH, "//input[@name='li1']")
first_checkbox.click()
second_checkbox = chrome_driver.find_element(By.XPATH, "//input[@name='li2']")
second_checkbox.click()
field = chrome_driver.find_element(By.XPATH, "//input[@id='sampletodotext']")
field.send_keys("testing")
button = chrome_driver.find_element(By.XPATH, "//input[@id='addbutton']")
button.click()
result = chrome_driver.find_element(By.XPATH, "//li[6]/span[@class='done-false']").text
assert 'testing' in result
sleep(5)
chrome_driver.close()
logger.info(
"Scenario is completed successfully"
)


# A sample test to verify the open API call
@pytest.mark.nondestructive
@pytest.mark.automated
Expand Down
15 changes: 12 additions & 3 deletions frontend/test_project/features/web/web_tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ Feature: OrangeHRM Login and Modus QA blog
And I click item 'Yes' for element 'Modus_Site > Careers > protection_dropdown'


@email @automated
Scenario: Email verification
When I get email for '[email protected]'
@email @automated @firefox
Scenario: Email Verification with email link
Given I set web base url '{%BASE_URL%}'
And Browser is maximized
And The title is 'OrangeHRM'
When The element 'OrangeHRM > username' is displayed
And I set text '{%HRM_USER_NAME%}' to field 'OrangeHRM > username'
And I set text '{%HRM_PASSWORD%}' to field 'OrangeHRM > password'
And I click on element 'OrangeHRM > login_button'
Then The title is 'OrangeHRM'
And The page url contains 'dashboard'
When I get link from email '[email protected]'
35 changes: 0 additions & 35 deletions main/frontend/common/step_definitions/browser_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


# WEB context Predefined Step
# ID 101, 102
@given(parsers.re("The browser resolution is '(?P<width>.*)' per '(?P<height>.*)'"),
converters=dict(width=data_manager.text_formatted, height=data_manager.text_formatted), )
@given(parsers.re("My screen resolution is '(?P<width>.*)' by '(?P<height>.*)' pixels"),
Expand All @@ -36,15 +35,13 @@ def window_size(width: int, height: int, selenium_generics: SeleniumGenerics):


# WEB context Predefined Step
# ID 103
@given("Browser is maximized")
@when("Browser is maximized")
def maximize(selenium_generics: SeleniumGenerics):
selenium_generics.maximize_window()


# WEB context Predefined Step
# ID 104
@given(parsers.re("I am on the (url|page|site) '(?P<page_url>.*)'"),
converters=dict(page_url=data_manager.text_formatted), )
@when(parsers.re("I am on the (url|page|site) '(?P<page_url>.*)'"),
Expand All @@ -60,7 +57,6 @@ def open_base_url(selenium_generics: SeleniumGenerics, base_url):


# WEB context Predefined Step
# ID 105
@given(parsers.re("I navigate to external page '(?P<url>.*)'"),
converters=dict(url=data_manager.text_formatted), )
@when(parsers.re("I navigate to external page '(?P<url>.*)'"),
Expand All @@ -70,7 +66,6 @@ def navigate_to_external_page(selenium_generics: SeleniumGenerics, url: str):


# WEB context Predefined Step
# ID 106
@given(parsers.re("I get current browser url and store it to '(?P<env_var>.*)'"))
@when(parsers.re("I get current browser url and store it to '(?P<env_var>.*)'"))
@then(parsers.re("I get current browser url and store it to '(?P<env_var>.*)'"))
Expand Down Expand Up @@ -121,7 +116,6 @@ def page_title_is_not(selenium_generics: SeleniumGenerics, soft_assert: str, tit


# WEB context Predefined Step
# ID 110
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that the title contains '(?P<title>.*)'"),
converters=dict(title=data_manager.text_formatted), )
def check_title_contains(selenium_generics: SeleniumGenerics, soft_assert: str, title: str):
Expand All @@ -133,7 +127,6 @@ def check_title_contains(selenium_generics: SeleniumGenerics, soft_assert: str,


# WEB context Predefined Step
# ID 111
@then(
parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that the title does not contain '(?P<title>.*)'"),
converters=dict(title=data_manager.text_formatted), )
Expand All @@ -146,7 +139,6 @@ def check_title_not_contains(selenium_generics: SeleniumGenerics, soft_assert: s


# WEB context Predefined Step
# ID 112
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is '(?P<url>.*)'"),
converters=dict(url=data_manager.text_formatted), )
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is '(?P<url>.*)'"),
Expand All @@ -162,7 +154,6 @@ def given_page_url_is(selenium_generics: SeleniumGenerics, soft_assert: str, url


# WEB context Predefined Step
# ID 113
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is not '(?P<url>.*)'"),
converters=dict(url=data_manager.text_formatted), )
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is not '(?P<url>.*)'"),
Expand All @@ -178,7 +169,6 @@ def given_page_url_is_not(selenium_generics: SeleniumGenerics, soft_assert: str,


# WEB context Predefined Step
# ID 114
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page (path is|url contains) '(?P<url>.*)'"),
converters=dict(url=data_manager.text_formatted), )
def check_page_url_contains(selenium_generics: SeleniumGenerics, soft_assert: str, url: str):
Expand All @@ -190,7 +180,6 @@ def check_page_url_contains(selenium_generics: SeleniumGenerics, soft_assert: st


# WEB context Predefined Step
# ID 115
@then(parsers.re(
"(With soft assertion '(?P<soft_assert>.*)' )?The page (path is not|url does not contain) '(?P<url>.*)'"),
converters=dict(url=data_manager.text_formatted), )
Expand All @@ -203,15 +192,13 @@ def check_page_url_not_contains(selenium_generics: SeleniumGenerics, soft_assert


# WEB context Predefined Step
# ID 116
@given(parsers.re("I refresh the current page"))
@when(parsers.re("I refresh the current page"))
def refresh_page(selenium_generics: SeleniumGenerics):
selenium_generics.refresh_page()


# WEB context Predefined Step
# ID 117
@given(parsers.re("There is just one (browser tab|window) open"))
@when(parsers.re("There is just one (browser tab|window) open"))
def close_all_but_first_tab(selenium_generics: SeleniumGenerics):
Expand All @@ -223,7 +210,6 @@ def close_all_but_first_tab(selenium_generics: SeleniumGenerics):


# WEB context Predefined Step
# ID 118
@given(parsers.re("I open new tab with url '(?P<page_url>.*)'"),
converters=dict(page_url=data_manager.text_formatted), )
@when(parsers.re("I open new tab with url '(?P<page_url>.*)'"),
Expand All @@ -233,7 +219,6 @@ def open_specific_tab(selenium_generics: SeleniumGenerics, base_url: str, page_u


# WEB context Predefined Step
# ID 119
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The url '(?P<url>.*)' is opened in a new (tab|window)"),
converters=dict(url=data_manager.text_formatted), )
def check_is_opened_in_new_window(selenium_generics: SeleniumGenerics, soft_assert: str, url: str):
Expand All @@ -246,7 +231,6 @@ def check_is_opened_in_new_window(selenium_generics: SeleniumGenerics, soft_asse


# WEB context Predefined Step
# ID 120
@given(parsers.re("I close the last opened window"))
@given(parsers.re("I close the last opened tab"))
@when(parsers.re("I close the last opened window"))
Expand All @@ -266,7 +250,6 @@ def switch_to_last(selenium_generics: SeleniumGenerics):


# WEB context Predefined Step
# ID 122
@then(parsers.re(
"(With soft assertion '(?P<soft_assert>.*)' )?There are '(?P<count>.*)' (tabs|windows) currently opened"),
converters=dict(count=data_manager.text_formatted))
Expand All @@ -279,7 +262,6 @@ def check_number_of_tabs(selenium_generics: SeleniumGenerics, soft_assert: str,


# WEB context Predefined Step
# ID 123
@given(parsers.re("I close the current opened tab"))
@when(parsers.re("I close the current opened tab"))
def close_current_opened_tab(selenium_generics: SeleniumGenerics):
Expand Down Expand Up @@ -367,7 +349,6 @@ def disable_cache(driver, cache_option: str):


# WEB context Predefined Step
# ID 132
@given(parsers.re("I attach file '(?P<file_path>.*)' to input field '(?P<locator_path>.*)'"),
converters=dict(file_path=data_manager.text_formatted), )
@when(parsers.re("I attach file '(?P<file_path>.*)' to input field '(?P<locator_path>.*)'"),
Expand All @@ -382,7 +363,6 @@ def attach_file(selenium_generics: SeleniumGenerics, file_path: str, locators: L


# WEB context Predefined Step
# ID 133
@given(parsers.re(
"(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' contains the value '(?P<value>.*)'"),
converters=dict(value=data_manager.text_formatted))
Expand All @@ -401,7 +381,6 @@ def check_cookie_content(selenium_generics: SeleniumGenerics, soft_assert: str,


# WEB context Predefined Step
# ID 134
@given(parsers.re(
"(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not contain the value '(?P<value>.*)'"),
converters=dict(value=data_manager.text_formatted))
Expand All @@ -420,7 +399,6 @@ def check_cookie_content_is_not(selenium_generics: SeleniumGenerics, soft_assert


# WEB context Predefined Step
# ID 135
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' exists"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' exists"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' exists"))
Expand All @@ -433,7 +411,6 @@ def check_cookie_exists(selenium_generics: SeleniumGenerics, soft_assert: str, n


# WEB context Predefined Step
# ID 136
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not exist"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not exist"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not exist"))
Expand All @@ -446,15 +423,13 @@ def check_cookie_does_not_exist(selenium_generics: SeleniumGenerics, soft_assert


# WEB context Predefined Step
# ID 137
@given("I fetch existing cookies from the site")
@when("I fetch existing cookies from the site")
def fetch_cookies(selenium_generics: SeleniumGenerics):
selenium_generics.get_all_cookies()


# WEB context Predefined Step
# ID 138, 139
@given(
parsers.re("I update the value of newly added cookie '(?P<name>.*)' with '(?P<value>.*)' for path '(?P<path>.*)'"),
converters=dict(value=data_manager.text_formatted))
Expand All @@ -470,15 +445,13 @@ def check_cookie_content(selenium_generics: SeleniumGenerics, name, value: str,


# WEB context Predefined Step
# ID 140
@given(parsers.re("I delete the cookie '(?P<name>.*)'"))
@when(parsers.re("I delete the cookie '(?P<name>.*)'"))
def delete_cookie(selenium_generics: SeleniumGenerics, name):
selenium_generics.delete_cookie(name)


# WEB context Predefined Step
# ID 141
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect the cookies to be present"))
def check_cookies_presence(selenium_generics: SeleniumGenerics, soft_assert: str):
if soft_assert is not None and soft_assert.lower() == 'true':
Expand All @@ -489,7 +462,6 @@ def check_cookies_presence(selenium_generics: SeleniumGenerics, soft_assert: str


# WEB context Predefined Step
# ID 142, 143
@then(parsers.re(
"(With soft assertion '(?P<soft_assert>.*)' )?I expect cookie '(?P<name>.*)' with value '(?P<value>.*)' to be present"),
converters=dict(value=data_manager.text_formatted))
Expand All @@ -505,7 +477,6 @@ def check_cookie_presence(selenium_generics: SeleniumGenerics, soft_assert: str,


# WEB context Predefined Step
# ID 144
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect cookie '(?P<name>.*)' to be deleted"))
def check_cookie_delete(selenium_generics: SeleniumGenerics, soft_assert: str, name):
if soft_assert is not None and soft_assert.lower() == 'true':
Expand All @@ -516,7 +487,6 @@ def check_cookie_delete(selenium_generics: SeleniumGenerics, soft_assert: str, n


# WEB context Predefined Step
# ID 145
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is opened"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is opened"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is opened"))
Expand All @@ -529,7 +499,6 @@ def step_presence_of_alert(selenium_generics: SeleniumGenerics, soft_assert: str


# WEB context Predefined Step
# ID 146
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is not opened"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is not opened"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is not opened"))
Expand All @@ -542,23 +511,20 @@ def check_modal_not_present(selenium_generics: SeleniumGenerics, soft_assert: st


# WEB context Predefined Step
# ID 147
@given(parsers.re("I accept popup (prompt|alertbox|confirmbox)"))
@when(parsers.re("I accept popup (prompt|alertbox|confirmbox)"))
def accept_alert(selenium_generics: SeleniumGenerics):
selenium_generics.accept_alert()


# WEB context Predefined Step
# ID 148
@given(parsers.re("I dismiss popup (prompt|alertbox|confirmbox)"))
@when(parsers.re("I dismiss popup (prompt|alertbox|confirmbox)"))
def dismiss_modal(selenium_generics: SeleniumGenerics):
selenium_generics.dismiss_alert()


# WEB context Predefined Step
# ID 149
@given(parsers.re("I enter '(?P<text>.*)' into popup (alertbox|confirmbox|prompt)"),
converters=dict(text=data_manager.text_formatted), )
@when(parsers.re("I enter '(?P<text>.*)' into popup (alertbox|confirmbox|prompt)"),
Expand All @@ -568,7 +534,6 @@ def check_modal(selenium_generics: SeleniumGenerics, text: str):


# WEB context Predefined Step
# ID 150, 151
@given(parsers.re("I set the (locale|language) for locators to '(?P<locale>.*)'"),
converters=dict(locale=data_manager.text_formatted), )
@when(parsers.re("I set the (locale|language) for locators to '(?P<locale>.*)'"),
Expand Down
Loading

0 comments on commit dabab93

Please sign in to comment.