Skip to content

Commit

Permalink
[qacode] fix for issue #150 + flake8 errors (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
netzulo authored Jun 10, 2018
1 parent a97028a commit 129dfec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 48 deletions.
32 changes: 21 additions & 11 deletions qacode/core/bots/modules/nav_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from qacode.core.exceptions.core_exception import CoreException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as EC
Expand Down Expand Up @@ -246,7 +247,7 @@ def reload(self):
"""Go reload page using browser functionality"""
self.driver.refresh()

def get_log(self, log_name='browser'):
def get_log(self, log_name='browser', raises=False):
"""Get selenium log by name, this depends of
driver mode and browser what it's using each time
Expand All @@ -260,16 +261,25 @@ def get_log(self, log_name='browser'):
Returns:
list() -- list of messages typed on a log_name
"""
if log_name == 'browser':
return self.driver.get_log(log_name)
if log_name == 'driver':
return self.driver.get_log(log_name)
if log_name == 'client':
return self.driver.get_log(log_name)
if log_name == 'server':
return self.driver.get_log(log_name)
raise CoreException(
'selenium log_name just can be: [browser,driver,client,server]')
try:
if log_name == 'browser':
return self.driver.get_log(log_name)
if log_name == 'driver':
return self.driver.get_log(log_name)
if log_name == 'client':
return self.driver.get_log(log_name)
if log_name == 'server':
return self.driver.get_log(log_name)
except WebDriverException as err:
msg = "nav | get_log: log_name={}, err={}"
self.log.warning(msg.format(log_name, err.msg))
# Selenium said, not all drivers will be handled
# by them with all options values
if raises:
raise CoreException(
("selenium log_name just can be:"
" [browser,driver,client,server]"))
return []

def get_screenshot_as_base64(self):
"""Gets the screenshot of the current window as a base64 encoded string
Expand Down
52 changes: 15 additions & 37 deletions tests/001_functionals/suite_004_navbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,71 +34,49 @@ def setup_method(self, test_method, close=True):

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_navbase_instance(self):
"""Testcase: test_000_navbase_instance"""
"""Testcase: test_navbase_instance"""
self.assert_is_instance(self.bot.navigation, NavBase)

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_gourl_without_waits(self):
"""Testcase: test_001_gourl_without_waitsparam"""
"""Testcase: test_gourl_without_waits"""
self.bot.navigation.get_url(self.page_home.get('url'))

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_gourl_with_waitsparam(self):
"""Testcase: test_002_gourl_with_waitsparam"""
"""Testcase: test_gourl_with_waitsparam"""
self.bot.navigation.get_url(
self.page_home.get('url'), wait_for_load=0)

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_getmaximizewindow(self):
"""Testcase: test_003_getmaximizewindow"""
"""Testcase: test_getmaximizewindow"""
self.bot.navigation.get_maximize_window()

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_getcapabilities(self):
"""Testcase: test_004_getcapabilities"""
"""Testcase: test_getcapabilities"""
caps = self.bot.navigation.get_capabilities()
self.assert_is_instance(caps, dict)
self.assert_is_instance(caps['chrome'], dict)
self.assert_equals(caps['browserName'], 'chrome')

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_getlog(self):
"""Testcase: test_005_getlog"""
def test_getlog_default(self):
"""Testcase: test_getlog_default"""
self.bot.navigation.get_url(self.page_home.get('url'))
log_data = self.bot.navigation.get_log()
self.assert_not_none(log_data)
self.log.debug("selenium logs, browser={}".format(log_data))

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_getlog_browser(self):
"""Testcase: test_006_getlog_browser"""
@pytest.mark.parametrize(
"log_name", ['browser', 'driver', 'client', 'server'])
def test_getlog_lognames(self, log_name):
"""Testcase: test_getlog_logname"""
self.bot.navigation.get_url(self.page_home.get('url'))
log_data = self.bot.navigation.get_log(log_name='browser')
log_data = self.bot.navigation.get_log(log_name=log_name)
self.assert_not_none(log_data)
self.log.debug("selenium logs, browser={}".format(log_data))

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_getlog_driver(self):
"""Testcase: test_007_getlog_driver"""
self.bot.navigation.get_url(self.page_home.get('url'))
log_data = self.bot.navigation.get_log(log_name='driver')
self.assert_not_none(log_data)
self.log.debug("selenium logs, driver={}".format(log_data))

@pytest.mark.skip('Issue opened on github selenium, waiting...')
def test_getlog_client(self):
"""Testcase: test_008_getlog_client
https://github.com/SeleniumHQ/selenium/issues/5410
"""
self.bot.navigation.get_url(self.page_home.get('url'))
log_data = self.bot.navigation.get_log(log_name='client')
self.assert_not_none(log_data)
self.log.debug("selenium logs, client={}".format(log_data))

@pytest.mark.skipIf(SKIP_REMOTES, SKIP_REMOTES_MSG)
def test_getlog_server(self):
"""Testcase: test_008_getlog_client"""
self.bot.navigation.get_url(self.page_home.get('url'))
log_data = self.bot.navigation.get_log(log_name='server')
self.assert_not_none(log_data)
self.log.debug("selenium logs, server={}".format(log_data))
msg = "selenium logs, log_name={}, log_data={}".format(
log_name, log_data)
self.log.debug(msg)

0 comments on commit 129dfec

Please sign in to comment.