Python write RF test - selenium library keyword encapsulation

Keywords: Selenium Attribute

A few days later, RF grafting to the original automated testing framework has been basically completed. Today, I will take some time to share the use of selenium library keyword

It is hoped that the second encapsulation and customized keywords will be helpful for you to do automatic test

Come on, talk too much, code:

# Get element information

def get_locator(self,locator):

ltype=locator["type"]

value=locator["value"]

return"%s=%s"%(ltype,value)

# Run tests

def test_run(self):

self.suite.run()

# Create a test

def testes_create(self,string):

test=self.suite.tests.create(string)

returntest

# Launch browser

def open_browser(self,http,browserName,obj):

# Test = self.tests'u create ("start browser")

obj.keywords.create("Open Browser",args=[http,browserName])

# Close browser

def close_browsers(self,test):

#Test = self.tests'u create ("close browser")

test.keywords.create("Close All Browsers")

# Browser maximization

def max_window(self,test):

# Test = self.tests'u create ("browser maximize")

test.keywords.create("Maximize Browser Window")

# Text input

def input_text(self,locator,text,test):

loc=self.get_locator(locator)

#Test = self.tests'u create ("text input")

test.keywords.create("Input Text",args=[loc,text])

# Click the button

def click_button(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("click button")

test.keywords.create("Click Button",args=[loc])

# Click elements

def click_element(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("click element")

test.keywords.create("Click Element",args=[loc])

# Wait for element to appear

def wait(self,locator,error,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("wait for element to appear")

test.keywords.create("Wait Until Page Contains Element",args=[loc,20,error])

# Get the title information of the browser window

def get_title(self):

test=self.testes_create("Obtain")

returntest.keywords.create("Get Title")

# Get element text information

def get_text(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("get element text information")

returntest.keywords.create("Get Text",args=[loc])

# Get element attribute value

def get_attribute(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("get element attribute value")

returntest.keywords.create("Get Element Attribute",args=[loc])

# Drop down box selection

def select_list(self,locator,value,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("drop-down box selection")

test.keywords.create("Unselect From List By Value",args=[loc+value])

# Form nesting

def select_frame(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("select form")

test.keywords.create("Select Frame",args=[loc])

# Exit form selection

def unselect_frame(self,test):

# Test = self.tests'u create ("exit form selection")

test.keywords.create("Unselect Frame")

# Click on the picture

def click_image(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("click image")

test.keywords.create("Click Image",args=[loc])

# Click on the link

def click_link(self,locator,test):

loc=self.get_locator(locator)

# Test = self.tests'u create ("click the link")

test.keywords.create("Click Link",args=[loc])

# Close the current pop-up window

def close_window(self,test):

test.keywords.create("Close_Window")

The above is the encapsulation of keywords. Careful partners will find that the keywords in selenium library do not have many operation keywords in actual projects, such as:
Window switching, mouse hovering and so on. At this time, you need to encapsulate and add to selenium library by yourself.
After that, I will explain how to customize keywords. Please support me a lot

Posted by grimmier on Sun, 03 May 2020 06:08:55 -0700