Giter Site home page Giter Site logo

webautomaiton's Introduction

WebAutomaiton

Web automation framework using python, selenium

2016/11/21 Made some changes on design pattern

Packaging page operations in parent class BasePage, like findelement:

def findElement(self,element):
    '''
    Find element

    element is a set with format (identifier type, value), e.g. ('id','username')

    Usage:
    self.findElement(element)
    '''
    try:
        type = element[0]
        value = element[1]
        if type == "id" or type == "ID" or type=="Id":
            elem = self.driver.find_element_by_id(value)

        elif type == "name" or type == "NAME" or type=="Name":
            elem = self.driver.find_element_by_name(value)

        elif type == "class" or type == "CLASS" or type=="Class":
            elem = self.driver.find_element_by_class_name(value)

        elif type == "link_text" or type == "LINK_TEXT" or type=="Link_text":
            elem = self.driver.find_element_by_link_text(value)

        elif type == "xpath" or type == "XPATH" or type=="Xpath":
            elem = self.driver.find_element_by_xpath(value)

        elif type == "css" or type == "CSS" or type=="Css":
            elem = self.driver.find_element_by_css_selector(value)
        else:
            raise NameError("Please correct the type in function parameter")
    except Exception:
        raise ValueError("No such element found"+ str(element))
    return elem

the sub class can inherit such functions and use them directly in its page operation:

class GoogleMainPage(BasePage):
"""description of class"""
searchbox = ('ID','lst-ib')

def __init__(self, browser = 'chrome'):
    super().__init__(browser)
    
def inputSearchContent(self,searchContent):
    searchBox = self.findElement(self.searchbox)
    self.type(searchBox,searchContent)
    self.enter(searchBox)

webautomaiton's People

Contributors

alvinxuch avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.