Skip to content

Commit

Permalink
Merge develop to master (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
pancht authored Feb 29, 2024
2 parents 79f4f29 + db1e136 commit 67cfab2
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ Installation
#. Rerun addition 2 times the tests which got failed (--reruns switch)
#. Target browser = Headless Chrome (--browser switch)

Notes for running -b=anti_bot_chrome:
- When running tests on anti_bot_chrome, suppress the python warnings by adding -W switch

.. code-block:: bash
- nrobo -b anti_bot_chrome -W ignore::DeprecationWarning
- `When running from a datacenter (even smaller ones), chances are large you will not pass! Also, if your ip reputation at home is low, you won't pass!
>`_
- anti_bot_chrome will not work with --grid switch!

.. Command Line Switches
Expand Down
29 changes: 29 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,35 @@ def driver(request):
service=ChromeService(
ChromeDriverManager().install(),
log_output=_driver_log_path))

elif browser == Browsers.ANTI_BOT_CHROME:
"""if browser requested is anti_bot_chrome"""

options = webdriver.ChromeOptions()
options.add_argument('--headless=new')
options = add_capabilities_from_file(options)

# enable/disable chrome options from a file
_browser_options = read_browser_config_options(
request.config.getoption(f"--{nCLI.BROWSER_CONFIG}"))
# apply chrome options
[options.add_argument(_option) for _option in _browser_options]

if _grid_server_url:
"""Get instance of remote webdriver"""
from nrobo import console
console.rule(f"[{STYLE.HLRed}]Anti-Bot Chrome is not supported by Grid Infrastructure![/]")
sys.exit()
# _driver = webdriver.Remote(_grid_server_url,
# options=options)
else:
"""Get instance of local chrom driver"""
import undetected_chromedriver as uc
_driver = uc.Chrome(use_subprocess=False, options=options)
# _driver = webdriver.Chrome(options=options,
# service=ChromeService(
# ChromeDriverManager().install(),
# log_output=_driver_log_path))
elif browser == Browsers.SAFARI:
"""if browser requested is safari"""

Expand Down
2 changes: 2 additions & 0 deletions nrobo/cli/install/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pytest==8.0.0
PyYAML==6.0.1
selenium==4.17.2
webdriver-manager==4.0.1
undetected-chromedriver==3.5.5
setuptools==69.1.1
selenium-page-factory==2.6
pytest-html==4.1.1
pytest-xdist==3.5.0
Expand Down
4 changes: 3 additions & 1 deletion nrobo/cli/nglobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Browsers:

CHROME = 'chrome'
CHROME_HEADLESS = "chrome_headless"
ANTI_BOT_CHROME = "anti_bot_chrome"
EDGE = 'edge'
FIREFOX = 'firefox'
FIREFOX_HEADLESS = "firefox_headless"
Expand All @@ -35,7 +36,8 @@ class Browsers:


# list holding supported browser in nRoBo framework
supported_browsers = [Browsers.CHROME, Browsers.CHROME_HEADLESS, Browsers.SAFARI,
supported_browsers = [Browsers.CHROME, Browsers.CHROME_HEADLESS, Browsers.ANTI_BOT_CHROME,
Browsers.SAFARI,
Browsers.FIREFOX, Browsers.FIREFOX_HEADLESS, Browsers.EDGE, Browsers.IE]
# # list holding browsers not supported in nRoBo framework
supported_browsers_in_future = [Browsers.OPERA]
Expand Down
4 changes: 2 additions & 2 deletions nrobo/cli/nrobo_args/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def nrobo_cli_parser(exit_on_failure=True):
parser.add_argument("-b", f"--{nCLI.BROWSER}", help="""
Target browser. Default is chrome.
Options could be:
{} | {} |
{} | {} | {} |
{} | {} | {} | {}
""".format(Browsers.CHROME, Browsers.CHROME_HEADLESS,
""".format(Browsers.CHROME, Browsers.CHROME_HEADLESS, Browsers.ANTI_BOT_CHROME,
Browsers.FIREFOX, Browsers.FIREFOX_HEADLESS,
Browsers.SAFARI, Browsers.EDGE))
parser.add_argument(f"--{nCLI.BROWSER_CONFIG}", help="""
Expand Down
15 changes: 14 additions & 1 deletion nrobo/selenese/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def frame(self, frame_reference: Union[str, int, WebElement]) -> None:

return self.driver.switch_to.frame(frame_reference)

def switch_to_new_window(self, type_hint: Optional[str] = None) -> None:
def switch_to_new_window(self, type_hint: Optional[str] = "window") -> None:
"""Switches to a new top-level browsing context.
The type hint can be one of "tab" or "window". If not specified the
Expand All @@ -288,6 +288,19 @@ def switch_to_new_window(self, type_hint: Optional[str] = None) -> None:
"""
self.driver.switch_to.new_window(type_hint)

def switch_to_new_tab(self) -> None:
"""
Create a new tab and switch to it.
:Usage:
::
switch_to_new_tab()
:return:
"""
self.switch_to_new_window("tab")

def switch_to_parent_frame(self) -> None:
"""Switches focus to the parent context. If the current context is the
top level browsing context, the context remains unchanged.
Expand Down
11 changes: 11 additions & 0 deletions tests/selenium_wrapper_nrobo_methods/test_browser_switches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from nrobo.framework.pages import Page


class TestBrowserSwitches:

def test_anti_bot_undetected_chrome(self, driver, logger):
page = Page(driver=driver, logger=logger)

page.get("https://nowsecure.nl")

page.wait_for_a_while(3)

0 comments on commit 67cfab2

Please sign in to comment.