Best Python code snippet using robotframework-anywherelibrary
BaseConfig.py
Source:BaseConfig.py  
1import json2import collections3from os import path4from selenium import webdriver5from selenium.webdriver.common.desired_capabilities import DesiredCapabilities6from selenium.webdriver.support.ui import WebDriverWait7from src.utilities.constant import Constant8class BaseConfig:9    __instance = None10    @staticmethod11    def get_instance():12        if BaseConfig.__instance is None:13            BaseConfig.__instance = BaseConfig()14        return BaseConfig.__instance15    def shut_down(self):16        BaseConfig.__driver.quit()17    def init_driver(self, **kwargs):18        config_dir = path.dirname(path.dirname(__file__))19        with open(path.join(config_dir, 'config_env_test.json')) as f:20            data_setup = json.load(f)21            initial_driver = None22            if data_setup['configInfo']['enableRemoteWebDriver']:23                remote_address = data_setup['remoteWebDriver']['remoteAddress']24                # desired_capabilities = data_setup['remoteWebDriver']['desiredCapabilities'][1] # Chrome25                desired_capabilities = {"browserName": kwargs["browser_name"], "platform": "ANY"}26                initial_driver = webdriver.Remote(command_executor=remote_address,27                                        desired_capabilities=desired_capabilities)28            else:29                browser_name = data_setup['localWebDriver']['browserName']30                if browser_name == Constant.CHROME_BROWSER:31                    initial_driver = webdriver.Chrome(executable_path=path.abspath("drivers/chromedriver.exe"))32                elif browser_name == Constant.FIREFOX_BROWSER:33                    initial_driver = webdriver.Firefox(executable_path=path.abspath("drivers/geckodriver.exe"))34                else:35                    raise KeyError("Browser name not found!")36            initial_wait = WebDriverWait(initial_driver, Constant.DRIVER_TIMEOUT)37            web_init = collections.namedtuple('WebInit', ['Driver', 'Wait'])38            return web_init(initial_driver, initial_wait)...driver_management.py
Source:driver_management.py  
1import json2import collections3from os import path4from selenium import webdriver5from selenium.webdriver.common.desired_capabilities import DesiredCapabilities6from selenium.webdriver.support.ui import WebDriverWait7from src.utilities.driver_constant import DriverConstant8from selenium.webdriver.android.webdriver import WebDriver as AndroidWebDriver9class DriverManagement:10    __instance = None11    @staticmethod12    def get_instance():13        if DriverManagement.__instance is None:14            DriverManagement.__instance = DriverManagement()15        return DriverManagement.__instance16    def init_driver(self, **kwargs):17        config_dir = path.dirname(path.dirname(__file__))18        with open(path.join(config_dir, 'config_env_test.json')) as f:19            data_setup = json.load(f)20            initial_driver = None21            browser_name = kwargs["browser_name"]22            if data_setup['config_info']['enable_remote_webdriver']:23                remote_address = data_setup['remote_webdriver']['remote_address']24                desired_capabilities = {"browserName": browser_name, "platform": "ANY"}25                initial_driver = webdriver.Remote(command_executor=remote_address, desired_capabilities=desired_capabilities)26            else:27                if browser_name == DriverConstant.CHROME_BROWSER:28                    initial_driver = webdriver.Chrome(executable_path=path.abspath("src/drivers/chromedriver.exe"))29                elif browser_name == DriverConstant.FIREFOX_BROWSER:30                    initial_driver = webdriver.Firefox(executable_path=path.abspath("src/drivers/geckodriver.exe"))31                else:32                    raise KeyError("Browser name not found!")33            initial_wait = WebDriverWait(initial_driver, DriverConstant.DRIVER_TIMEOUT)34            web_browser_init = collections.namedtuple('WebInit', ['Driver', 'Wait'])35            return web_browser_init(initial_driver, initial_wait)...spaceship_purchase.py
Source:spaceship_purchase.py  
1def checkio(offers):2    '''3       the amount of money that Petr will pay for the ride4    '''5    initial_petr, raise_petr, initial_driver, reduction_driver = offers6    while initial_petr < initial_driver:7        if (initial_petr + raise_petr) >= initial_driver:8            return initial_driver9        initial_petr += raise_petr10        initial_driver -= reduction_driver11    return initial_petr12if __name__ == '__main__':13    assert checkio([150, 50, 1000, 100]) == 450, 'First'14    assert checkio([150, 50, 900, 100]) == 400, 'Second'15    print('All is ok')16    ...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
