Exemple #1
0
class TestGetDetails(softest.TestCase):
    log = customLogger(logging.INFO)

    @pytest.fixture(autouse=True)
    def class_level_setup(self, class_level_setup):
        self.read_prop = ReadConfig()
        url = self.read_prop.get_property_value("QA_ENVIRONMENT",
                                                "application_url")
        print("application_url is", url)
        self.driver.get(url)
        print("application_url is Opened now ", url)

    @pytest.mark.smoke
    def test_method_cybage(self):
        obj = DeskBoardOR(self.driver, self.log)
        obj.google_search_box_set_value("Cybage")
        print(self.driver.title)

    @pytest.mark.smoke
    def test_method_selenium(self):
        obj = DeskBoardOR(self.driver, self.log)
        obj.google_search_box_set_value("selenium")
        print(self.driver.title)

    @pytest.mark.smoke
    def test_method_python(self):
        obj = DeskBoardOR(self.driver, self.log)
        obj.google_search_box_set_value("python")
        print(self.driver.title)
Exemple #2
0
    def capture_screenshot(driver: webdriver, title: str):
        """
        This method captures screenshot and copied it at given location.
        """
        try:
            log = customLogger(logging.INFO)
            log.info("Capturing the screen shot of failed test case '" +
                     title + "'.")
            # Get path of screen shot folder
            paths = GetPath()
            os = GenericFunctions.get_os()
            screenshot_folder = paths.screenshot_folder_path()

            # create screenshot name using title and timestamp
            # current_date = "_".join(re.split(" |\:|\.", str(GenericFunctions.get_current_date_time())))
            current_date = GenericFunctions.get_filename_datetimestamp()
            if os.casefold() == 'windows':
                screenshot_name = "\\" + title + "_" + current_date + ".png"
            else:
                screenshot_name = "/" + title + "_" + current_date + ".png"
            screenshot_path = screenshot_folder + screenshot_name
            log.info("Screenshot path: " + screenshot_path)

            if driver is not None:
                driver.save_screenshot(screenshot_path)
            else:
                log.error("Driver is None ")
        except Exception as e:
            log.error("Capture Screenshot exception: " + str(e))
        return screenshot_path
Exemple #3
0
class HeaderPage(BasePageOR):
    """
    this is Object repository of Header Section
    """

    log = customLogger(logging.INFO)

    def __init__(self, driver, log):
        self.driver = driver
        self.log = log
        super().__init__(driver=self.driver, log=self.log)
Exemple #4
0
class SeleniumWebDriver:
    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        self.driver = driver

    def getByType(self, locatorType):
        locatorType = locatorType.lower()
        if locatorType == "id":
            return By.ID
        elif locatorType == "name":
            return By.NAME
        elif locatorType == "xpath":
            return By.XPATH
        else:
            self.log.error("Locator type " + locatorType +
                           " not correct/supported")
        return False

    def getElement(self, locator, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            byType = self.getByType(locatorType)
            element = self.driver.find_element(byType, locator)
            self.log.info("Element Found with locator: " + locator +
                          " and  locatorType: " + locatorType)
        except:
            self.log.error("Element not found with locator: " + locator +
                           " and  locatorType: " + locatorType)
        return element

    def elementClick(self, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.click()
            self.log.info("Clicked on element with locator: " + locator +
                          " locatorType: " + locatorType)
        except:
            self.log.error("Cannot click on the element with locator: " +
                           locator + " locatorType: " + locatorType)
            print_stack()

    def sendKeys(self, data, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.send_keys(data)
            self.log.info("Sent data on element with locator: " + locator +
                          " locatorType: " + locatorType)
        except:
            self.log.error("Cannot send data on the element with locator: " +
                           locator + " locatorType: " + locatorType)
            print_stack()
Exemple #5
0
class LoginPage(SeleniumDriver):

    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    # Locators
    _login_link = "Login"
    _email_field = "user_email"
    _password_field = "user_password"
    _login_button = "commit"
    _profile_xpath = ".//*[@id='navbar']//span[text()='Rakesh Kushwaha']"
    _log_out_button = " Log Out   "

    def clickLoginLink(self):
        self.elementClick(self._login_link, locatorType="link")

    def enterEmail(self, email):
        self.sendKeys(email, self._email_field)

    def enterPassword(self, password):
        self.sendKeys(password, self._password_field)

    def clickLoginButton(self):
        self.elementClick(self._login_button, locatorType="name")

    def logout(self):
        self.elementClick(self._profile_xpath, locatorType="xpath")
        self.elementClick(self._log_out_button, locatorType="link")

    def login(self, email, password):
        self.waitForElement(self._login_link)
        self.clickLoginLink()

        self.enterEmail(email)
        self.enterPassword(password)
        self.clickLoginButton()

    def verifyLoginSucess(self):
        result = self.isElementPresent(
            ".//*[@id='navbar']//span[text()='Rakesh Kushwaha']",
            locatorType="xpath")
        return result

    def verifyLoginfailure(self):
        result = self.isElementPresent(
            ".//div[contains(text(),'Invalid email or password')]",
            locatorType="xpath")
        return result
Exemple #6
0
class BasePageOR:
    """
    Elements for this page is defined in base_enum

    """
    log = customLogger(logging.INFO)

    def __init__(self, driver, log):
        self.driver = driver
        self.log = log
        self.actions = SeleniumUtils(self.driver, self.log)

    def is_error_displayed(self):
        return self.actions.is_element_present(BaseEnum.ERROR_MESSAGE.value[0],
                                               BaseEnum.ERROR_MESSAGE.value[1])
Exemple #7
0
class DeskBoardOR(BasePageOR):
    """
    this is Object repository of Header Section
    """

    log = customLogger(logging.INFO)

    def __init__(self, driver, log):
        self.driver = driver
        self.log = log
        super().__init__(driver=self.driver, log=self.log)

    def google_search_box_set_value(self, text):
        self.actions.enter_text(DeskBoardEnum.searchBox.value[0],
                                DeskBoardEnum.searchBox.value[1], text)
        self.actions.submit_element(DeskBoardEnum.searchBox.value[0],
                                    DeskBoardEnum.searchBox.value[1])
Exemple #8
0
class TestDemo3(BaseClass):
    log = customLogger(logLevel=logging.DEBUG)

    def test_ValidateRadio(self):
        demo = Demo3(self.driver)
        self.log.info("Validate Radio test")
        assert demo.RadioButton() == True

    def test_Scrolling(self):
        demo = Demo3(self.driver)
        self.log.info("Scrolling test")
        demo.MouseHover()

    def test_Scroll(self):
        demo = Demo3(self.driver)
        self.log.info("Scrolling test")
        demo.MouseHover()
class ReadConfig:
    log = customLogger(logging.INFO)

    def get_config_file(self):
        """
        Get config.ini
        """
        try:
            paths = GetPath()
            config_file_path = paths.config_path()
            config = configparser.RawConfigParser()
            config.read(config_file_path)
            return config
        except Exception as e:
            self.log.error("Error while reading config.ini file" + str(e))
            return None

    def get_property_value(self, section: str, key: str) -> str:
        """
        Returns property value for give key.
        If key is password first it decrypt the encrypted password and return it
        """
        try:
            config = self.get_config_file()
            value = config.get(section, key)
            if 'password' in key.casefold():
                decrypt_key = (config.get(section, key + "_key"))
                password = GenericFunctions.decrypt_value(decrypt_key, value)
                if password is not None:
                    return password
                else:
                    raise Exception(
                        "Password Key is None. Please check password key is valid or not."
                    )

            else:
                return value
        except Exception as e:
            self.log.error("Error while reading config.ini file" + str(e))
            return None
Exemple #10
0
class SeleniumDriver():
    log=cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        self.driver = driver

    def getByType(self, locatorType):
        locatorType = locatorType.lower()
        if locatorType == "id":
            return By.ID
        elif locatorType == "name":
            return By.NAME
        elif locatorType == "xpath":
            return By.XPATH
        elif locatorType == "css":
            return By.CSS_SELECTOR
        elif locatorType == "class":
            return By.CLASS_NAME
        elif locatorType == "link":
            return By.LINK_TEXT
        else:
            self.log.info("Locator type " + locatorType + " not correct/supported")
        return False

    def getElement(self, locator, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            byType = self.getByType(locatorType)
            element = self.driver.find_element(byType, locator)
            self.log.info("Element Found with locator: " + locator + " and  locatorType: " + locatorType)
        except:
            self.log.error("Element not found with locator: " + locator + " and  locatorType: " + locatorType)
        return element

    def elementClick(self, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.click()
            self.log.info("Clicked on element with locator: " + locator + " locatorType: " + locatorType)
        except:
            self.log.error("Cannot click on the element with locator: " + locator + " locatorType: " + locatorType)


    def sendKeys(self, data, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.clear()
            element.send_keys(data)
            self.log.info("Sent data on element with locator: " + locator + " locatorType: " + locatorType)
        except:
            self.log.error("Cannot send data on the element with locator: " + locator +
                  " locatorType: " + locatorType)


    def isElementPresent(self, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            if element is not None:
                self.log.info("Element Found")
                return True
            else:
                self.log.error("Element not found")
                return False
        except:
            self.log.error("Element not found")
            return False

    def elementPresenceCheck(self, locator, byType):
        try:
            elementList = self.driver.find_elements(byType, locator)
            if len(elementList) > 0:
                self.log.info("Element Found")
                return True
            else:
                self.log.error("Element not found")
                return False
        except:
            self.log.error("Element not found")
            return False

    def waitForElement(self, locator, locatorType="id",
                               timeout=20, pollFrequency=0.5):
        element = None
        try:
            byType = self.getByType(locatorType)
            self.log.info("Waiting for maximum :: " + str(timeout) +
                  " :: seconds for element to be clickable")
            wait = WebDriverWait(self.driver, timeout, poll_frequency=pollFrequency,
                                 ignored_exceptions=[NoSuchElementException,
                                                     ElementNotVisibleException,
                                                     ElementNotSelectableException])
            element = wait.until(EC.element_to_be_clickable((byType, locator)))
            self.log.error("Element appeared on the web page")
        except:
            self.log.error("Element not appeared on the web page")

        return element
Exemple #11
0
class Utility:
    log = customLogger(logLevel=logging.DEBUG)

    def __init__(self, driver):
        self.driver = driver

    def getByType(self, locatorType):
        locatorType = locatorType.lower()
        if locatorType == 'id':
            return By.ID
        elif locatorType == 'name':
            return By.NAME
        elif locatorType == 'xpath':
            return By.XPATH
        elif locatorType == 'css':
            return By.CSS_SELECTOR
        elif locatorType == 'class':
            return By.CLASS_NAME
        elif locatorType == 'link':
            return By.LINK_TEXT
        elif locatorType == 'plink':
            return By.PARTIAL_LINK_TEXT
        else:
            self.log.info("Locator type"+ locatorType +" is not correct / supported")
        return False

    def getElement(self, locator, locatorType="id"):
        element = None
        try:
            byType = self.getByType(locatorType)
            element = self.driver.find_element(byType, locator)
            self.log.info("Element is found with locator: " + locator + " and locator Type:" +locatorType)
        except:
            self.log.info("Element is not found with locator: " + locator + " and locator Type:" +locatorType)
        return element

    def clickElement(self, locator, locatorType="id"):
        try:
            self.waitForElementToClickable(locator, locatorType)
            element = self.getElement(locator, locatorType)
            element.click()
            self.log.info("Element is clicked")
        except:
            self.log.info("Element is not clicked with locator:"+locator+" and locator type:"+locatorType)

    def sendKeys(self, data, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.send_keys(data)
            self.log.info("Sent data '"+data+"' on element with locator :"+locator+ " and locator type :"+locatorType)
        except:
            self.log.info("Can not sent data '"+data+"' on element with locator :"+locator+ " and locator type :"+locatorType)

    def waitForElementToClickable(self, locator, locatorType="id", timeOut=60, pollingFre=2):
        byType = self.getByType(locatorType)
        wait = WebDriverWait(self.driver, timeout=timeOut, poll_frequency=pollingFre, ignored_exceptions=
        [NoSuchElementException, ElementNotVisibleException])
        wait.until(EC.element_to_be_clickable((byType, locator)))

    def moveToElement(self, locator, locatorType="id"):
        element = self.getElement(locator, locatorType)
        try:
            action = ActionChains(self.driver)
            self.log.info("Move to element is working in Try block")
            action.move_to_element(element).perform()
        except:
            self.log.info("Move to element is working in Except block")
            self.driver.execute_script("arguments[0].scrollIntoView(true);", element)

    def takeScreenshot(self):
        fileName = str(round(time.time() * 1000 )) + ".png"
        screenshotDirectory = r"C:\Users\gktom\Desktop\test"
        name = screenshotDirectory + "\\" +fileName
        self.driver.save_screenshot(name)

        """try:
from object_repository.header_section.header_or import HeaderPage
from object_repository.login_page.login_page_or import LoginPageOR
from selenium_base.path import GetPath
from selenium_base.take_screenshot import CaptureScreenShot
from selenium_base.webdriver_factory import DriverFactory
from utilities.generate_allure_report.generate_complete_execution_report import AllureReport
from utilities.klov_reports import Reports
from utilities.logger import customLogger
from utilities.move_to_archive import MoveToArchiveFolder
from utilities.read_config import ReadConfig
from utilities.read_excel import get_testcaseid
from utilities.testrail import APIClient

driver = None
_LOG = customLogger(logging.INFO)
environment = None
report = None
klov_server = None


def init_report():
    read_prop = ReadConfig()
    projectName = read_prop.get_property_value("REPORT", "projectName")
    reportName = read_prop.get_property_value("REPORT", "reportName")
    mongoDbHost = read_prop.get_property_value("REPORT", "mongoDbHost")
    mongoDbPort = int(read_prop.get_property_value("REPORT", "mongoDbPort"))
    klovServerAddress = read_prop.get_property_value("REPORT",
                                                     "klovServerAddress")
    return Reports(projectName, reportName, mongoDbHost, mongoDbPort,
                   klovServerAddress)
Exemple #13
0
class DriverFactory():
    log = customLogger(logging.INFO)

    def driver_initialize(self, browser: str, test_name: str = None):
        """
        This method initialize web driver of provided browser.
        And Maximize the browser window.

        :return: webdriver
        """
        global readProp
        try:
            if browser is not None:
                browser = browser.casefold()
            default = "Incorrect browser name"
            return getattr(self, 'init_' + browser, lambda: default)()
        except Exception as e:
            self.log.error("Driver error: " + str(e))
        return None

    # def desired_capabilities(self, test_name: str):
    #     desired_cap = {}
    #     # 'os_version': '8.1',
    #     # 'resolution': '1920x1080',
    #     # 'browser': 'Firefox',
    #     # 'browser_version': 'latest',
    #     # 'os': 'Windows',
    #     # 'name': test_name,  # test name
    #     # 'browserstack.debug': False
    #     # # 'build': 'BStack Build Number 1'  # CI/CD job or build name
    #     # }
    #     desired_cap.update(resolution=readProp.get_property_value('CAPABILITIES', "resolution"))
    #     desired_cap.update(browser=readProp.get_property_value('CAPABILITIES', "browser"))
    #     desired_cap.update(os=readProp.get_property_value('CAPABILITIES', "os"))
    #     desired_cap.update(name=test_name)
    #     return desired_cap

    def desired_capabilities(self):
        desired_cap = {}
        desired_cap.update(
            os=readProp.get_property_value('CAPABILITIES', "os"))
        desired_cap.update(os_version=readProp.get_property_value(
            'CAPABILITIES', "os_version"))
        desired_cap.update(resolution=readProp.get_property_value(
            'CAPABILITIES', "resolution"))
        desired_cap.update(
            browser=readProp.get_property_value('CAPABILITIES', "browser"))
        desired_cap.update(browser_version=readProp.get_property_value(
            'CAPABILITIES', "browser_version"))
        desired_cap.update(
            name=readProp.get_property_value('CAPABILITIES', "name"))
        desired_cap.update(
            build=readProp.get_property_value('CAPABILITIES', "build"))
        return desired_cap

    def init_firefox(self):
        self.log.info("Launching FireFox browser")
        driver = webdriver.Firefox(
            executable_path=GeckoDriverManager().install())
        return driver

    def init_chrome(self):
        self.log.info("Launching Chrome browser")
        driver = webdriver.Chrome(ChromeDriverManager().install())
        # NOTE: Use above code to initialize chrome driver. Below code for chrome driver is temporary
        # driver = webdriver.Chrome(executable_path="D:\\PDS\\Automation\\PDSF_Automation\\drivers\\chromedriver.exe")
        # driver = webdriver.Chrome(executable_path="/home/nareshy/pythonAutomation/PDSF_Automation/drivers/chromedriver.exe")

        driver.maximize_window()
        return driver

    def init_ie(self):
        self.log.info("Launching Internet Explorer browser")
        driver = webdriver.Ie(IEDriverManager().install())
        driver.maximize_window()
        return driver

    def init_lambdatest(self, test_name):
        # Lambda Test tool code
        username = readProp.get_property_value('LAMBDA_TEST', "username")
        access_key = readProp.get_property_value('LAMBDA_TEST', "access_key")
        selenium_endpoint = "http://{}:{}@hub.lambdatest.com/wd/hub".format(
            username, access_key)
        executor = RemoteConnection(selenium_endpoint, resolve_ip=False)
        driver = webdriver.Remote(
            command_executor=executor,
            desired_capabilities=self.desired_capabilities(test_name))

        # Borwoserstack code
        # driver = webdriver.Remote(
        #     command_executor='https://*****:*****@hub-cloud.browserstack.com/wd/hub',
        #     desired_capabilities=self.desired_capabilities(test_name))
        return driver

    def init_bs(self):
        self.log.info("Launching  browser in Browser Stack")
        access_url = readProp.get_property_value('BROWSER_STACK', "access_url")
        driver = webdriver.Remote(
            command_executor=access_url,
            desired_capabilities=self.desired_capabilities())
        return driver