Skip to content

Commit

Permalink
Merge pull request #68 from jacebrowning/handle-unspecified-browser
Browse files Browse the repository at this point in the history
Handle unspecified browser
  • Loading branch information
jacebrowning authored Jan 29, 2021
2 parents 1b0e31b + 1ac8232 commit db7745f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 30 deletions.
21 changes: 12 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pomace/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def launch() -> Browser:
if not settings.browser.name:
sys.exit("No browser specified")

if settings.browser.name == "open":
settings.browser.name = NAMES[0]

settings.browser.name = settings.browser.name.lower()
log.info(f"Launching browser: {settings.browser.name}")

try:
Expand Down
7 changes: 7 additions & 0 deletions pomace/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class Action:
def sorted_locators(self) -> List[Locator]:
return [x for x in sorted(self.locators, reverse=True) if x]

@property
def locator(self) -> Locator:
try:
return self.sorted_locators[0]
except IndexError:
return Locator("id", "placeholder")

def __post_init__(self):
if self.verb and self._verb != Verb.TYPE and not self.sorted_locators:
if settings.dev:
Expand Down
6 changes: 3 additions & 3 deletions pomace/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def browser_if_unset():
return

if "CI" in os.environ or not bullet:
settings.browser.name = os.getenv("BROWSER", "firefox")
value = os.getenv("BROWSER") or browser.NAMES[0]
settings.browser.name = value.lower()
return

shared.linebreak = False
Expand All @@ -60,8 +61,7 @@ def browser_if_unset():
bullet=" ● ",
choices=browser.NAMES,
)
value = command.launch()
settings.browser.name = value.lower()
settings.browser.name = command.launch()


@offset
Expand Down
28 changes: 28 additions & 0 deletions pomace/tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# pylint: disable=unused-variable,expression-not-assigned

from pomace import browser
from pomace.config import settings


def describe_launch():
def it_requires_a_browser_to_be_set(expect):
settings.browser.name = ""
with expect.raises(SystemExit):
browser.launch()

def it_rejects_invalid_browsers(expect):
settings.browser.name = "foobar"
with expect.raises(SystemExit):
browser.launch()

def it_forces_lowercase_browser_name(expect, mocker):
settings.browser.name = "Firefox"
mocker.patch.object(browser, "Browser")
browser.launch()
expect(settings.browser.name) == "firefox"

def it_handles_unspecified_browser(expect, mocker):
settings.browser.name = "open"
mocker.patch.object(browser, "Browser")
browser.launch()
expect(settings.browser.name) == "firefox"
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "pomace"
version = "0.6.9"
version = "0.6.10"
description = "Dynamic page objects for browser automation."

license = "MIT"
Expand Down Expand Up @@ -78,7 +78,7 @@ pylint = "~2.6.0"
# Testing
pytest = "^5.4.3"
pytest-cov = "*"
pytest-describe = "^1.0"
pytest-describe = { git = "https://github.com/pytest-dev/pytest-describe", rev = "9014bf3ee564518aad3622b5f035f7ca6139e398" }
pytest-expecter = "^2.0"
pytest-mock = "^2.0"
pytest-random = "*"
Expand Down
16 changes: 0 additions & 16 deletions tests/test_browser.py

This file was deleted.

0 comments on commit db7745f

Please sign in to comment.