Skip to content

Commit

Permalink
added --appium switch
Browse files Browse the repository at this point in the history
  • Loading branch information
pancht committed Mar 7, 2024
1 parent 1384207 commit 3140218
Show file tree
Hide file tree
Showing 29 changed files with 203 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,4 @@ results-unittests/
/key/BigQueryCredentialLink
/key/nrobo-statistics-214a0f5d2c1b.json
/key/experiments/pytest/
node_modules/
8 changes: 1 addition & 7 deletions cli/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,7 @@ def copy_conftest_file() -> None:
def delete_dist_folder() -> None:
"""Deletes dist folder for vacating space for fresh packages."""

if os.environ[EnvKeys.HOST_PLATFORM] in [PLATFORMS.DARWIN, PLATFORMS.LINUX, PLATFORMS.MACOS]:
try:
remove_files_recursively(__DIST_DIR__)
except Exception as e:
print(e)
elif os.environ[EnvKeys.HOST_PLATFORM] in [PLATFORMS.WINDOWS]:
terminal(["del", "/q", "/S", __DIST_DIR__ + os.sep + "*.*"])
remove_files_recursively(__DIST_DIR__)


def run_build_command() -> None:
Expand Down
70 changes: 53 additions & 17 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import nrobo.cli.detection as detect

from nrobo.util.constants import CONST
from nrobo.appium import AUTOMATION_NAMES, CAPABILITY


def update_pytest_life_cycle_log(life_cycle_item: str, item_type: str = "fixture"):
Expand Down Expand Up @@ -128,17 +129,25 @@ def add_capabilities_from_file(options):
and return updated options"""
from nrobo.util.common import Common
from nrobo import NROBO_PATHS, Environment, EnvKeys
if detect.production_machine() and not detect.developer_machine():
capabilities = Common.read_yaml(NROBO_PATHS.EXEC_DIR / NROBO_PATHS.CAPABILITY_YAML)
else:
capabilities = Common.read_yaml(
NROBO_PATHS.NROBO_DIR / NROBO_PATHS.NROBO / NROBO_PATHS.CAPABILITY_YAML)
capabilities = Common.read_yaml(NROBO_PATHS.EXEC_DIR / NROBO_PATHS.CAPABILITY_YAML)

for k, v in capabilities.items():
options.set_capability(k, v)

return options


def get_appium_capabilities_from_file():
"""Read appium capabilities from appium_capability.yaml file
return appium_capabilities"""
from nrobo.util.common import Common
from nrobo import NROBO_PATHS, Environment, EnvKeys
capabilities = Common.read_yaml(NROBO_PATHS.EXEC_DIR / NROBO_PATHS.CAPABILITY_APPIUM_YAML)

return capabilities


def pytest_addoption(parser):
"""
Pass different values to a test function, depending on command line options
Expand All @@ -149,6 +158,13 @@ def pytest_addoption(parser):
update_pytest_life_cycle_log("pytest_addoption", "hook")

group = parser.getgroup("nrobo header options")
# nRoBo appium options
group.addoption(
f"--{nCLI.APPIUM}", help=f"Tells nRoBo to trigger via appium client",
action="store_true", default=False
)

# nRoBo webdriver options
group.addoption(
f"--{nCLI.BROWSER}", help="""
Target browser name. Default is chrome.
Expand All @@ -169,6 +185,7 @@ def pytest_addoption(parser):
help="Take full page screenshot", action="store_true", default=False)

# ini option
parser.addini(f"--{nCLI.APPIUM}", type='bool', help=f"Tells nRoBo to trigger via appium client")
parser.addini(f"{nCLI.APP}", type="string",
help="Name of your app project under test")
parser.addini(f"{nCLI.REPORT_TITLE}", type="string",
Expand Down Expand Up @@ -263,7 +280,20 @@ def driver(request):
NREPORT.LOG_DIR_DRIVER + os.sep + \
test_method_name + NREPORT.LOG_EXTENTION

if browser == Browsers.CHROME:
if bool(os.environ[EnvKeys.APPIUM]):
"""get appium driver with given capabilities"""
from appium import webdriver as _webdriver

capabilities = get_appium_capabilities_from_file()

if capabilities[CAPABILITY.AUTOMATION_NAME] == AUTOMATION_NAMES.UI_AUTOMATION2:
"""Create uiautomator2 driver instance"""
from appium.options.android import UiAutomator2Options

options = UiAutomator2Options().load_capabilities(capabilities)
_driver = _webdriver.Remote(_grid_server_url, options=options)

elif browser == Browsers.CHROME:
"""if browser requested is chrome"""

options = webdriver.ChromeOptions()
Expand All @@ -285,6 +315,7 @@ def driver(request):
service=ChromeService(
ChromeDriverManager().install(),
log_output=_driver_log_path))

elif browser == Browsers.CHROME_HEADLESS:
"""if browser requested is chrome"""

Expand Down Expand Up @@ -337,6 +368,7 @@ def driver(request):
# service=ChromeService(
# ChromeDriverManager().install(),
# log_output=_driver_log_path))

elif browser == Browsers.SAFARI:
"""if browser requested is safari"""

Expand Down Expand Up @@ -382,6 +414,7 @@ def driver(request):
"""Get instance of local firefox driver"""
_service = webdriver.FirefoxService(log_output=_driver_log_path, service_args=['--log', 'debug'])
_driver = webdriver.Firefox(options=options, service=_service)

elif browser == Browsers.EDGE:
"""if browser requested is microsoft edge"""

Expand All @@ -401,6 +434,7 @@ def driver(request):
"""Get instance of local firefox driver"""
_service = webdriver.EdgeService(log_output=_driver_log_path)
_driver = webdriver.Edge(options=options, service=_service)

elif browser == Browsers.IE:
"""if browser requested is microsoft internet explorer"""

Expand Down Expand Up @@ -429,6 +463,7 @@ def driver(request):
"""Get instance of local firefox driver"""
_service = webdriver.IeService(log_output=_driver_log_path)
_driver = webdriver.Ie(options=options)

else:
from nrobo.cli.tools import console
console.rule(f"[{STYLE.HLRed}]DriverNotConfigured Error!")
Expand Down Expand Up @@ -578,6 +613,7 @@ def pytest_configure(config):

os.environ[EnvKeys.TITLE] = str(config.getoption(f'--{nCLI.REPORT_TITLE}')).replace(CONST.UNDERSCORE, CONST.SPACE)
os.environ[EnvKeys.APP] = str(config.getoption(f'--{nCLI.APP}')).replace(CONST.UNDERSCORE, CONST.SPACE)
os.environ[EnvKeys.APPIUM] = str(config.getoption(f'--{nCLI.APPIUM}'))

# add custom markers
config.addinivalue_line("markers", "sanity: marks as sanity test")
Expand Down Expand Up @@ -632,17 +668,17 @@ def pytest_runtest_setup(item):
fixtureinfo = None

update_pytest_life_cycle_log_with_value(f"Function properties:\n"
f"name={item.name}\n"
f"parent={item.parent}\n"
f"config={item.config}\n"
f"callspec={callspec}\n"
f"callobj={callobj}\n"
f"keywords={item.keywords}\n"
f"session={item.session}\n"
f"fixtureinfo={fixtureinfo}\n"
f"originalname={item.originalname}\n"
f"filepath={item.fspath}\n"
f"docstring={item.__doc__}")
f"name={item.name}\n"
f"parent={item.parent}\n"
f"config={item.config}\n"
f"callspec={callspec}\n"
f"callobj={callobj}\n"
f"keywords={item.keywords}\n"
f"session={item.session}\n"
f"fixtureinfo={fixtureinfo}\n"
f"originalname={item.originalname}\n"
f"filepath={item.fspath}\n"
f"docstring={item.__doc__}")

pprint(item.__doc__)
pprint(item.config)
Expand Down
5 changes: 5 additions & 0 deletions nrobo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class EnvKeys:
and many more such...
"""
APPIUM = "appium"
PIP_COMMAND = "Pip Command"
EXEC_DIR = "Execution Directory"
NROBO_DIR = "nRoBo Installation Directory"
Expand All @@ -70,6 +71,7 @@ class EnvKeys:


# load environment keys with defaults
os.environ[EnvKeys.APPIUM] = "False"
os.environ[EnvKeys.PIP_COMMAND] = Python.PIP
os.environ[EnvKeys.EXEC_DIR] = ""
os.environ[EnvKeys.NROBO_DIR] = ""
Expand All @@ -90,11 +92,13 @@ class NROBO_PATHS:
"""nRoBo framework directories and files"""
EXEC_DIR = Path(os.environ[EnvKeys.EXEC_DIR])
NROBO_DIR = Path(os.environ[EnvKeys.NROBO_DIR])
NODE_MODULES = Path("node_modules")
PATCHES = Path("patches")
NROBO = Path("nrobo")
INIT_PY = Path("__init__.py")
BROWSER_CONFIGS = Path("browserConfigs")
CAPABILITY_YAML = BROWSER_CONFIGS / "capability.yaml"
CAPABILITY_APPIUM_YAML = BROWSER_CONFIGS / "appium_capability.yaml"
MARKERS_YAML = BROWSER_CONFIGS / "markers.yaml"

# Browsers packages
Expand Down Expand Up @@ -139,6 +143,7 @@ class NROBO_PATHS:
FRAMEWORK_PAGES = FRAMEWORK / PAGES
FRAMEWORK_PAGE_PYPI_HOME_PY_FILE = FRAMEWORK_PAGES / Path("PagePyPiHome.py")
TESTS = Path("tests")
MOBILE = Path("mobile")
FRAMEWORK_TESTS = FRAMEWORK / TESTS
GUI = FRAMEWORK_TESTS / Path("gui")
GUI_PKG = GUI / INIT_PY
Expand Down
25 changes: 25 additions & 0 deletions nrobo/appium/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
=====================CAUTION=======================
DO NOT DELETE THIS FILE SINCE IT IS PART OF NROBO
FRAMEWORK AND IT MAY CHANGE IN THE FUTURE UPGRADES
OF NROBO FRAMEWORK. THUS, TO BE ABLE TO SAFELY UPGRADE
TO LATEST NROBO VERSION, PLEASE DO NOT DELETE THIS
FILE OR ALTER ITS LOCATION OR ALTER ITS CONTENT!!!
===================================================
appium module holds nRoBo settings needed for
working with appium framework.
@author: Panchdev Singh Chauhan
@email: erpanchdev@gmail.com
"""


class CAPABILITY:
AUTOMATION_NAME = 'automationName'


class AUTOMATION_NAMES:
"""Possible appium capabilities for automationName"""

UI_AUTOMATION2 = 'uiautomator2'
7 changes: 7 additions & 0 deletions nrobo/browserConfigs/appium_capability.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
platformName: Android
automationName: uiautomator2
deviceName: Android
appPackage: com.android.settings
appActivity: .Settings
language: en
locale: US
2 changes: 1 addition & 1 deletion nrobo/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():
greet_the_guest()

# install dependencies
install_nrobo(None)
install_nrobo(install_only=True)

# verify python installation and version
verify_set_python_install_pip_command()
Expand Down
8 changes: 7 additions & 1 deletion nrobo/cli/cli_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class nCLI:
Make sure that the same option is also removed from the
nCLI.ARGS dictionary too!!!"""

NPM = "npm"
APPIUM = "appium"
INSTALL = "install"
APP = "app"
URL = "url"
Expand All @@ -66,6 +68,8 @@ class nCLI:
MARKER = "marker"

ARGS = {
NPM: NPM,
APPIUM: APPIUM,
INSTALL: INSTALL,
APP: APP,
URL: URL,
Expand Down Expand Up @@ -102,4 +106,6 @@ class PACKAGES:
"""nRoBo packages"""

NROBO = "nrobo"
CLI = "cli"
CLI = "cli"

APPIUM = ['appium']
7 changes: 6 additions & 1 deletion nrobo/cli/install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def transfer_files_to_host_project() -> None:
print(f"Installation complete")


def install_nrobo(requirements_file: Optional[str] = None) -> None:
def install_nrobo(requirements_file: Optional[str] = None, install_only: bool = False) -> None:
"""This will install nrobo framework and its dependencies on host system in the current directory
from where nrobo command was executed in the Production environment.
Expand Down Expand Up @@ -211,6 +211,11 @@ def install_nrobo(requirements_file: Optional[str] = None) -> None:
print(f"Requirements are not installed successfully!")
return

if install_only:
# No need to install or upgrade framework
# Just return after installing requirements
return

if detect.production_machine():
"""Install or upgrading framework on Production environment"""

Expand Down
2 changes: 1 addition & 1 deletion nrobo/cli/install/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ pycurl==7.45.3
pypinfo==21.0.0
pytest-emoji==0.2.0
npm==0.1.1

Appium-Python-Client==3.2.1
Loading

0 comments on commit 3140218

Please sign in to comment.