diff --git a/.travis.yml b/.travis.yml index 934c3bbc..323fa59b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,18 @@ language: python cache: pip +env: + - MOZ_HEADLESS=1 +addons: + firefox: latest os: - linux python: - 3.6 +before_install: + - wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz + - mkdir geckodriver + - tar -xzf geckodriver-v0.24.0-linux64.tar.gz -C geckodriver + - export PATH=$PATH:$PWD/geckodriver install: - pip install -r requirements.txt - pip install flake8 diff --git a/core/browserEngine.py b/core/browserEngine.py new file mode 100644 index 00000000..8d923363 --- /dev/null +++ b/core/browserEngine.py @@ -0,0 +1,56 @@ +import re +import os +import sys + +from core.log import setup_logger +from core.utils import writer +from selenium import webdriver +from selenium.webdriver.firefox.options import Options +from selenium.common.exceptions import UnexpectedAlertPresentException +from selenium.webdriver.support import expected_conditions as EC + + +def init_browser(): + global browser + options = Options() + options.add_argument('--headless') + browser = webdriver.Firefox(options=options) + + +def kill_browser(): + if browser is not None: + browser.quit() + + +def browser_engine(response): + _write_response_to_file(response) + navigate_to('file://' + sys.path[0] + '/test.html') + os.remove('test.html') + popUp = False + actions = webdriver.ActionChains(browser) + + try: + actions.move_by_offset(2, 2) + actions.perform() + if EC.alert_is_present(): + popUp = True + + except UnexpectedAlertPresentException: + popUp = True + + return popUp + + +def _write_response_to_file(response): + response = re.sub(r'', '