Skip to content

Prodigy qa #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: surevs-patch-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 104 additions & 45 deletions prodigyqa/browseractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ def get_attribute(self, locator=None, element=None,
"""Fetch attribute from locator/element/parent.

element with child locator.
:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:param attribute_name: attribute name to get it's vale
:param element: it is a webelement
:param type : value can only be 'locator' or 'element' or 'mixed'
:type locator: dict
:type locator:dict
:type type: str
"""
valid_arguments_of_type = ['locator', 'element', 'mixed']
Expand Down Expand Up @@ -213,8 +213,9 @@ def get_attribute(self, locator=None, element=None,
def click(self, locator, index=None):
"""Click an element.

:param locator: dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}) or
webelement.
:param index: Defaults None, number/position of element
"""
self.page_readiness_wait()
Expand All @@ -231,14 +232,23 @@ def click(self, locator, index=None):
self.__find_element(locator).click()
elif isinstance(locator, WebElement):
locator.click()
elif isinstance(locator, list):
if index is not None:
if index < len(locator):
locator[index].click()
else:
raise AssertionError(
"Index is greater than no. of elements present")
else:
locator[0].click()
else:
raise AssertionError(
"Dictionary/Weblement are valid Locator types.")

def javascript_click(self, locator, index=None):
"""Javascript Click on provided element.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'})
or a Webelement.
:param index: Number/position of element present
Expand All @@ -260,77 +270,113 @@ def javascript_click(self, locator, index=None):
self.by_value, value=locator['locatorvalue']))
elif isinstance(locator, WebElement):
self.__execute_script("arguments[0].click();", locator)
elif isinstance(locator, list):
if index is not None:
if index < len(locator):
self.driver.execute_script(
"arguments[0].click();", locator[index])
else:
raise AssertionError(
"Index is greater than no. of elements present")
else:
self.driver.execute_script(
"arguments[0].click();", locator[0])
else:
raise AssertionError(
"Locator type should be either dictionary or Weblement.")

def is_element_displayed(self, locator: dict):
def is_element_displayed(self, locator, index=None):
"""
Check whether an element is diplayed.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.locator_check(locator)
self.page_readiness_wait()
if isinstance(locator, dict):
return self.driver.find_element(
self.by_value,
value=locator['locatorvalue']).is_displayed()
self.locator_check(locator)
if index is not None:
web_elts = self.find_elements(locator)
if index < len(web_elts):
return web_elts[index].is_displayed()
else:
raise AssertionError(
"Index is greater than the number of elements")
else:
return self.driver.find_element(
self.by_value,
value=locator['locatorvalue']).is_displayed()
elif isinstance(locator, WebElement):
locator.is_displayed()
elif isinstance(locator, list):
if index is not None:
if index < len(locator):
return locator[index].is_displayed()
else:
raise AssertionError(
"Index is greater than no. of elements present")
else:
return locator[0].is_displayed()
else:
raise AssertionError("Locator type should be dictionary.")

def is_element_enabled(self, locator: dict):
def is_element_enabled(self, locator):
"""
Check whether an element is enabled.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.locator_check(locator)
self.page_readiness_wait()
if isinstance(locator, dict):
return self.__find_element(locator).is_enabled()
elif isinstance(locator, WebElement):
locator.is_enabled()
else:
raise AssertionError("Locator type should be dictionary.")

def is_element_selected(self, locator: dict):
"""
Check whether an element is selecte.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.locator_check(locator)
self.page_readiness_wait()
if isinstance(locator, dict):
return self.__find_element(locator).is_selected()
elif isinstance(locator, WebElement):
locator.is_selected()
else:
raise AssertionError("Locator type should be dictionary.")

def send_keys(self, locator: dict, value=None):
"""Send text but does not clear the existing text.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.page_readiness_wait()
if isinstance(locator, dict):
self.locator_check(locator)

self.__find_element(locator).send_keys(
locator['value'] if value is None else value)
elif isinstance(locator, WebElement):
locator.send_keys(value)
else:
raise AssertionError("Locator type should be dictionary.")

def get_text(self, locator, index=None):
"""Get text from provided Locator.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
"""
self.page_readiness_wait()
Expand All @@ -345,7 +391,6 @@ def get_text(self, locator, index=None):
"Index is greater than the number of elements")
else:
return self.__find_element(locator).text

elif isinstance(locator, WebElement):
return locator.text
else:
Expand Down Expand Up @@ -401,17 +446,19 @@ def get_domain_url(self):
url = self.driver.current_url
return url.split('//')[0] + '//' + url.split('/')[2]

def clear_text(self, locator: dict):
def clear_text(self, locator):
"""Clear the text if it's a text entry element.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.locator_check(locator)
self.page_readiness_wait()
if isinstance(locator, dict):
return self.__find_element(locator).clear()
elif isinstance(locator, WebElement):
locator.clear()
else:
raise AssertionError("Locator type should be dictionary")

Expand Down Expand Up @@ -510,9 +557,9 @@ def switch_to_alert(self):
def hover_on_element(self, locator: dict):
"""Hover on a particular element.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.locator_check(locator)
self.page_readiness_wait()
Expand All @@ -530,7 +577,7 @@ def hover_on_element(self, locator: dict):
def hover_on_click(self, locator):
"""Hover & click a particular element.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
"""
self.locator_check(locator)
Expand All @@ -546,7 +593,7 @@ def hover_on_click(self, locator):
def wait_for_element(self, locator) -> bool:
"""Wait for an element to exist in UI.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:rtype: bool
"""
Expand Down Expand Up @@ -582,10 +629,10 @@ def wait_and_reject_alert(self):
def select_option_by_index(self, locator: dict, index: int):
"""Select the option by index.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:param index: integer value for index.
:type locator: dict
:type locator:dict
:type index: int
"""
self.by_value = locator['by']
Expand All @@ -600,34 +647,34 @@ def select_option_by_index(self, locator: dict, index: int):
AssertionError(
"Invalid locator '{}' or index '{}'".format(locator, index))

def select_option_by_value(self, locator: dict, value: int):
def select_option_by_value(self, locator: dict, value):
"""Select the option by using value.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:param value: string value to select option.
:type locator: dict
:type locator:dict
:type value: int
"""
self.page_readiness_wait()
if isinstance(locator, dict) and isinstance(value, int):
if isinstance(locator, dict):
self.locator_check(locator)
try:
Select(self.__find_element(locator)).select_by_value(value)

Select(self.__find_element(locator)
).select_by_value(value)
except selenium_exceptions.NoSuchElementException:
logger.error("Exception : Element '{}' Not Found".format(
locator['by'] + '=' + locator['locatorvalue']))
else:
AssertionError(
"Invalid locator '{}' or value '{}'".format(locator, value))
AssertionError("Invalid locator type")

def select_option_by_text(self, locator: dict, text):
"""Select the value by using text.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:param text: string value to select option.
:type locator: dict
:type locator:dict
"""
self.page_readiness_wait()
if isinstance(locator, dict):
Expand All @@ -653,9 +700,9 @@ def scroll_to_footer(self):
def find_elements(self, locator: dict):
"""Return elements matched with locator.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.locator_check(locator)
self.page_readiness_wait()
Expand All @@ -669,9 +716,9 @@ def find_elements(self, locator: dict):
def scroll_to_element(self, locator: dict):
"""Scroll to a particular element on the page.

:param locator: dictionary of identifier type
:param locator:dictionary of identifier type
and value ({'by':'id', 'value':'start-of-content.'}).
:type locator: dict
:type locator:dict
"""
self.page_readiness_wait()
if isinstance(locator, dict):
Expand All @@ -692,7 +739,7 @@ def scroll_to_element(self, locator: dict):
def __find_element(self, locator: dict):
"""Private method simplified finding element.

:type locator: dict
:type locator:dict
"""
if isinstance(locator, dict):
self.locator_check(locator)
Expand All @@ -715,3 +762,15 @@ def __execute_script(self, script, web_elm=None):
return self.driver.execute_script(
script,
self.__find_element(web_elm))

def get_list_size(self, locator: dict):
"""
Get List Size of provided locator.
:param locator: must contain the valid locator.
"""
self.locator_check(locator)
self.page_readiness_wait()
if isinstance(locator, dict):
return len(self.find_elements(locator))
else:
AssertionError("Invalid locator type")
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pycodestyle<2.6.0,>=2.5.0
pandas==0.24.2
urllib3==1.25.7
requests>=2.21.0
ipdb==0.12.2
ipdb==0.13.2
pytest>=4.0.2
pytest-html<2.1.0
pytest-html<2.2.0
xlrd>=0.9.0
scrapy
loguru
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='prodigyqa',
version='1.2.2',
version='1.3.0',
description='Test Automation Framework',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down Expand Up @@ -55,9 +55,9 @@
'pandas==0.24.2',
'urllib3==1.25.7',
'requests>=2.21.0',
'ipdb==0.12.2',
'ipdb==0.13.2',
'pytest>=4.0.2',
'pytest-html<2.1.0',
'pytest-html<2.2.0',
'xlrd>=0.9.0',
'scrapy',
'nltk',
Expand Down