Example #1
0
    def __complete_mobile_search(self, close=False):
        self.__sys_out("Starting mobile search", 1)

        try:
            driver = Driver.get_driver(self.path, Driver.MOBILE_DEVICE,
                                       self.headless)
            self.__login(driver)

            self.completion.mobile_search = self.__search(
                driver, Driver.MOBILE_DEVICE)
            if self.completion.mobile_search:
                self.__sys_out("Successfully completed mobile search", 1, True)
            else:
                self.__sys_out("Failed to complete mobile search", 1, True)
        except:
            try:
                Driver.close(driver)
            except:  # not yet initialized
                pass
            raise

        if close:
            Driver.close(driver)
        else:
            return driver
Example #2
0
def taxi_random():
    agent = Random()
    driver = Driver({
        'epochs': 1000,
        'env': gym.make('Taxi-v2'),
        'agent': agent,
    })
    driver.run_taxi_random()
Example #3
0
 def complete_web_search_and_offers(self, search_hist, print_stats=True):
     self.search_hist = search_hist
     self.__complete_edge_search(close=True)
     driver = self.__complete_web_search()
     self.__complete_offers(driver)
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
Example #4
0
 def complete_both_searches(self, search_hist, print_stats=True):
     self.search_hist = search_hist
     self.__complete_edge_search()
     self.__complete_web_search(close=True)
     driver = self.__complete_mobile_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
Example #5
0
 def complete_all(self, print_stats=True):
     driver = self.__complete_web_search()
     self.__complete_offers(driver)
     Driver.close(driver)
     driver = self.__complete_mobile_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
Example #6
0
def cartpole_random():
    agent = Random()
    driver = Driver({
        'epochs': 1000,
        'env': gym.make('CartPole-v1'),
        'agent': agent,
    })
    driver.run_cartpole_random()
Example #7
0
def frozen_lake_random():
    agent = Random()
    driver = Driver({
        'epochs': 1000,
        'env': gym.make('FrozenLake-v0'),
        'agent': agent,
    })
    driver.run_frozen_lake_random()
Example #8
0
 def __init__(self, driver=None):
     if driver:
         self.driver = driver
     else:
         self.driver = Driver()
     if self.URL:
         self.driver.driver.get(self.URL)
     self.logger = logging.getLogger(str(settings.PROJECT_DIR))
     self.logger.info(f'Class \'{self.__class__.__name__}\' successfully initialized.')
Example #9
0
def taxi_qlearner():
    agent = Qlearner({
        'alpha': 0.1,
        'gamma': 0.6,
        'epsilon': 0.1,
    })
    driver = Driver({
        'epochs': 10000,
        'env': gym.make('Taxi-v2'),
        'agent': agent,
    })
    driver.run_taxi_qlearner()
Example #10
0
def cartpole_tdlearner():
    agent = TDlearner({
        'alpha': 0.2,
        'gamma': 0.5,
        'epsilon': 0.1,
    })
    driver = Driver({
        'epochs': 50000,
        'env': gym.make('CartPole-v1'),
        'agent': agent,
    })
    driver.run_cartpole_tdlearner()
Example #11
0
def frozen_lake_qlearner():
    agent = Qlearner({
        'alpha': 0.1,
        'gamma': 0.6,
        'epsilon': 0.3,
    })
    driver = Driver({
        'epochs': 10000,
        'env': gym.make('FrozenLake-v0'),
        'agent': agent,
    })
    driver.run_frozen_lake_qlearner()
Example #12
0
    def __complete_web_search(self, driver=None, close=False):
        self.__sys_out("Starting web search", 1)

        try:
            if driver is None:
                driver = Driver.get_driver(self.path, Driver.WEB_DEVICE,
                                           self.headless)
                self.__login(driver)
            self.completion.web_search = self.__search(driver,
                                                       Driver.WEB_DEVICE)
            if self.completion.web_search:
                self.__sys_out("Successfully completed web search", 1, True)
            else:
                self.__sys_out("Failed to complete web search", 1, True)
        except:
            try:
                driver.quit()
            except:  # not yet initialized
                pass
            raise

        if close:
            driver.quit()
        else:
            return driver
Example #13
0
 def __init__(self):
     self.config_path = Path("./src/configs/")
     self.scrape_items = []
     self.files = self.load_files()
     self.driver = Driver()
     self.scrapers = None
     self.setup()
     self.scrapers = init_scrapers(self.driver, self.scrape_items)
Example #14
0
def single_run(params):
    print(params)
    medical_cost = MedicalCost()
    driver = Driver(params, medical_cost.data)

    driver.train()
    driver.report()

    inputs = medical_cost.data.sample(10)
    driver.predict(inputs)
Example #15
0
class BasePage:
    """ Base web page that opens window with desired URL and it has methods to work with elements using xpath. """

    URL = None
    """ str: If set, after initialization of page object, browser is redirected to this URL. """

    def __init__(self, driver=None):
        if driver:
            self.driver = driver
        else:
            self.driver = Driver()
        if self.URL:
            self.driver.driver.get(self.URL)
        self.logger = logging.getLogger(str(settings.PROJECT_DIR))
        self.logger.info(f'Class \'{self.__class__.__name__}\' successfully initialized.')

    def close(self):
        self.driver.close()

    def get_element_by_xpath(self, xpath):
        return WebDriverWait(self.driver, 20).until(
            EC.presence_of_element_located((By.XPATH, xpath))
        )

    def get_elements_by_xpath(self, xpath):
        return self.driver.driver.find_elements_by_xpath(xpath)

    def click_element_by_xpath(self, xpath, scroll_to=False):
        if scroll_to:
            self.scroll_to_element_by_xpath(xpath)
            time.sleep(1)
        self.driver.execute_script("arguments[0].click();", self.get_element_by_xpath(xpath))
        time.sleep(0.3)

    def scroll_to_element_by_xpath(self, xpath):
        self.driver.execute_script(
            'arguments[0].scrollIntoView({behavior: "smooth"});', self.get_element_by_xpath(xpath)
        )

    def set_value_by_xpath(self, xpath, value):
        elem = self.get_element_by_xpath(xpath)
        elem.clear()
        elem.send_keys(value)
        time.sleep(0.3)

    @staticmethod
    def get_child_by_xpath(elem, xpath):
        return WebDriverWait(elem, 10).until(lambda _: elem.find_element_by_xpath(xpath))

    def click_child_by_xpath(self, elem, xpath):
        self.driver.execute_script('arguments[0].click();', self.get_child_by_xpath(elem, xpath))

    def get_child_text_by_xpath(self, elem, xpath):
        return self.get_child_by_xpath(elem, xpath).text
Example #16
0
    def __init__(self, instrument, mode='all', pricebuffer_size=1000, tick_source=None, **params):
        self.buffer = PriceBuffer(size=pricebuffer_size)
        self.instrument = tuple(instrument)
        self.mode = mode
        self.params = params

        self.trades = []
        if tick_source:
            self.tick_source = Driver.init_module_config(tick_source)
        else:
            self.tick_source = None
Example #17
0
    def __complete_offers(self, driver=None):
        self.__sys_out("Starting offers", 1)

        try:
            if not driver:
                driver = Driver.get_driver(self.path, Driver.WEB_DEVICE,
                                           self.headless)
                self.__login(driver)

            self.completion.offers = self.__offers(driver)
            if self.completion.offers == -1 or self.completion.offers == False:
                self.__sys_out("Failed to complete offers", 1, True)
            else:
                self.__sys_out("Successfully completed offers", 1, True)
        except:
            try:
                Driver.close(driver)
            except:
                pass
            raise

        return driver
    def __init__(self,
                 instrument,
                 mode='all',
                 pricebuffer_size=1000,
                 tick_source=None,
                 **params):
        self.buffer = PriceBuffer(size=pricebuffer_size)
        self.instrument = tuple(instrument)
        self.mode = mode
        self.params = params

        self.trades = []
        if tick_source:
            self.tick_source = Driver.init_module_config(tick_source)
        else:
            self.tick_source = None
Example #19
0
    def reset_broker(self):
        self.account_id = None
        self.account_name = 'Local test'
        self.account_currency = self.param_account_currency
        self.margin_rate = self.param_margin_rate

        self.balance = self.param_account_balance
        self.margin_available = self.param_account_balance
        self.margin_used = 0.0

        self.open_orders = 0
        self.open_orders_list = []
        self.open_trades = 0
        self.open_trades_list = []
        self.trade_id = 0

        self.realized_pl = 0
        self.unrealized_pl = 0

        self.tick_source = Driver.init_module_config(self.param_tick_source)

        self.stat = Stat(self.param_account_balance)
        self.last_tick = {}
Example #20
0
    def __init__(self, account_balance, margin_rate, tick_source, account_currency="EUR"):
        self.account_id = None
        self.account_name = 'Local test'
        self.account_currency = account_currency
        self.margin_rate = margin_rate

        self.balance = account_balance
        self.margin_available = account_balance
        self.margin_used = 0.0

        self.open_orders = 0
        self.open_orders_list = []
        self.open_trades = 0
        self.open_trades_list = []

        self.realized_pl = 0
        self.unrealized_pl = 0

        self.tick_source = Driver.init_module_config(tick_source)

        self.stat = Stat(account_balance)
        self.last_tick = {}

        self.logger = logging.getLogger(__name__)
Example #21
0
 def __init__(self, file_path, web_path, maximum):
     self.driver = Driver(file_path, web_path)
     self.maximum = maximum
Example #22
0
File: FXT.py Project: bluecube/FXT
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging

from src.driver import Driver

FORMAT = '%(asctime)s %(name)s: %(message)s'
logging.basicConfig(format=FORMAT)

driver = Driver()
driver.start()

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
Example #23
0
 def complete_mobile_search(self, print_stats=True):
     driver = self.__complete_mobile_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
Example #24
0
 def complete_offers(self, print_stats=True):
     driver = self.__complete_offers()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
Example #25
0
 def complete_web_search_and_offers(self, print_stats=True):
     driver = self.__complete_web_search()
     self.__complete_offers(driver)
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
Example #26
0
 def complete_web_search(self, search_hist, print_stats=True):
     self.search_hist = search_hist
     driver = self.__complete_web_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
                        type=str,
                        help='Recipient email address for error emails.')
    parser.add_argument('-a',
                        '--from-password',
                        type=str,
                        help='Password of sender email account.')
    parser.add_argument('-e',
                        '--headless',
                        action='store_true',
                        default=False,
                        help='Run browser in headless mode.')
    return parser.parse_args()


if __name__ == '__main__':

    _init_logging()
    args = _parse_args()
    driver = Driver(headless=args.headless)
    try:
        GSLoginPage(driver=driver).login(args.name, args.password)
        GSChallengesPage(driver=driver).process_all_challenges()
    except Exception as e:
        logging.getLogger(str(settings.PROJECT_DIR)).error(
            f'Because of following error, automation is stopped and email is sent: {e}'
        )
        send_error_email(args.from_address, args.from_password,
                         args.to_address, str(e))
    finally:
        driver.close()
Example #28
0
import os
import sys
import getopt

path = os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-1])
if path not in sys.path:
    sys.path.append(path)

from src.driver import Driver

driver = Driver()
driver.run_all_handler()
Example #29
0
    def test_github(self):
        driver = Driver.create_driver()
        try:
            element = driver.find_element_by_xpath("//a[@href='/login']")
            self.soft_assert(self.assertIsNotNone, element, msg="Not able to find sign in element")
            element.click()
            self.soft_assert(self.assertIsNotNone, driver.find_element_by_id("login"), msg="Not able to find login page"
                                                                                           " element")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_1.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 1 : Verify that by clicking on Sign in button user is redirected"
                           " to login page", exc_info=ex)

        try:
            driver.find_element_by_name("commit").click()
            self.soft_assert(self.assertIsNotNone, driver.find_element_by_id("js-flash-container"),
                             msg="Error message is not present.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_2.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 2 : Verify that username and password fields are mandatory"
                           " in login page", exc_info=ex)

        try:
            driver.find_element_by_class_name("label-link").click()
            driver.find_element_by_id("email_field").send_keys("*****@*****.**")
            driver.find_element_by_name("commit").click()
            self.soft_assert(self.assertIsNotNone, driver.find_element_by_id("js-flash-container"),
                             msg="Error message is not present.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_3.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 3 : Verify that inserting m.ie into email field in "
                           "reset_password page displays message Can't find that email, sorry.", exc_info=ex)

        try:
            driver.find_element_by_id("email_field").send_keys("")
            driver.find_element_by_name("commit").click()
            # print(driver.find_element_by_xpath("//div[@id='js-flash-container']/div").__getattribute__("text"))
            self.soft_assert(self.assertIsNotNone, driver.find_element_by_id("js-flash-container"),
                             msg="Error message is not present.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_4.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 4 : Verify that inserting empty value into email field in "
                           "reset_password page displays message Can't find that email, sorry.", exc_info=ex)

        try:
            driver.find_element_by_id("email_field").send_keys("")
            driver.find_element_by_name("commit").click()
            message = driver.find_element_by_xpath("//div[@id='js-flash-container']/div").__getattribute__("text")
            self.soft_assert(self.assertTrue, True if "address is not a verified" in message else False,
                             msg="Error message is not verified.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_5.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 5 :  Verify that the first word in error message in "
                           "reset_password page is 'address is not a verified'", exc_info=ex)

        try:
            driver.get("https://github.com/")
            driver.find_element_by_xpath("//a[@href='/login']/../div/../a[2]").click()
            self.soft_assert(self.assertIsNotNone, driver.find_element_by_xpath("//div[text()='Join GitHub']"),
                             msg="Jojn Github page is not opened.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_6.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 6 : Verify that clicking on Sign up button will redirect user "
                           "into join github page", exc_info=ex)

        try:
            self.soft_assert(self.assertIsNotNone, driver.find_element_by_xpath("//h1[text()='Create your account']"),
                             msg="Create your account text is not present.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_7.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 7 : Verify that join github page contains text "
                           "Create your personal account", exc_info=ex)

        try:
            driver.find_element_by_id("user_email").send_keys("xyz")
            self.soft_assert(self.assertTrue, driver.find_element_by_id("signup_button").get_attribute("disabled"),
                             msg="Create account button is not disabled.")
            self.assert_all()
            driver.get_screenshot_as_file(str(Path.home()) + "/Documents/GitTest/image/testcase_8.png")
        except Exception as ex:
            logger.warning("Failed to verify test case 8 : Verify that Create an account button is greyed when an "
                           "existing email address is inserted in join github page.", exc_info=ex)