佟希吧 关注:5贴子:18
  • 0回复贴,共1

基于pthon的selenium测试

只看楼主收藏回复

第一个文件
from Logon import log_on
count=log_on()
username=""
password=""
brower="Chrome"
process='清洗'
place='沪太路'
height='空'
count.log_on_brower(username,password)
count.Container_management_section(process,place,height)
第二个文件
#coding=utf-8
#Class name: log_on
#Description: logon BaoLan system,Process operation module,
#Parameters:N/A
#Return:N/A
#Sample:
#Author:CC
#History : republic, version 1.0. 2017/03/06
from selenium import webdriver
from time import sleep,strftime,ctime
from element_locations import element_location
from selenium.webdriver.common.action_chains import ActionChains
class log_on(element_location):
driver = webdriver.Chrome()
# Function name:log_on_brower
# Description: logon system
# Parameters:N/A
# Return:N/A
# Sample: N/A
# Author:republic
# History : republic, version 1.0. 2017/03/06
def log_on_brower(self,username,password):
base_url=""
driver=self.driver
driver.get(base_url)
#input username
driver.find_element_by_name("loginname").send_keys(username)
#input passwd
driver.find_element_by_name("passwd").send_keys(password)
#click submit button
driver.find_element_by_name("passwd").submit()
#window zoom
driver.maximize_window()
sleep(2)
#Function name:Container_management_section
#Description: Process operation module
#Parameters:N/A
#Return:N/A
#Sample: N/A
#Author:republic
#History : republic, version 1.0. 2015/03/06
def Container_management_section(self,process,place,height):
driver=self.driver
#click Container management
driver.find_element_by_partial_link_text("集装箱管理").click()
driver.implicitly_wait(10)
#click increase button
self.element_Xpath('//*[@id="content"]/div/div[3]/div/span/button[1]').click()
#input Container number
self.element_Xpath('/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[1]/input').send_keys("NPCU1263370")
#select customer name
self.element_Xpath('/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[2]/input[2]').click()
#search customer name
self.element_Xpath('/html/body/div[4]/div/div/div/div/div/div[2]/form/div/div/div[1]/div/div/div/div/div[1]/input').send_keys("中化")
#sumber
self.element_Xpath('/html/body/div[4]/div/div/div/div/div/div[2]/form/div/div/div[1]/div/div/div/div/div[5]/button').click()
sleep(3)
#--------------------------------------------------------------------------------------------------------------------------
self.element_Xpath('/html/body/div[4]/div/div/div/div/div/div[2]/form/div/div/div[2]/div[1]/div/div/table/tbody/tr[1]/td[1]/input').click()
#-------------------------------------------------------------------------------------------------------------------------
# 查找客户名称----这个地方要注意下我脚本默认选的第一个下次我再优化
self.element_Xpath('/html/body/div[4]/div/div/div/div/div/div[2]/div/button[1]').click()
#--------------------------------------------------------------------------------------------------------------------------
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[4]/input").send_keys("20150309")
#-------------------------------------------------------------------------------------------------------------------
if place == "沪太路":
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[9]/select/option[2]").click()
elif process == '金勺路':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[9]/select/option[3]").click()
elif process == '石太路':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[9]/select/option[4]").click()
if process=='清洗':
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[1]").click()
#计划提箱
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[1]/input").send_keys("20150315")
#工时
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[5]/input").send_keys("4")
#前装货
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[5]/input").send_keys("油漆")
#项目
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[2]/input").send_keys("油漆")
# 点击空重
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[7]/select").click()
if height=='空':
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[7]/select/option[2]").click()
else:
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[7]/select/option[3]").click
print("OK")
#下单时间
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[4]/input").send_keys('20150301')
#洗箱人
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[6]/input").send_keys("杨")
#费用
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[8]/input").send_keys("4")
#费用美元
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[2]/div[1]/div[9]/input").send_keys("5")
#点击空重
print("OK")
self.element_Xpath("/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[1]/div[6]/input").send_keys("李")
sleep(5)
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/div/button[1]").click()
elif process=='修理':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[2]").click()
elif process=='年检':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[3]").click()
elif process=='加热':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[4]").click()
elif process=='油漆':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[5]").click()
elif process=='清洁检验':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[6]").click()
elif process=='起租':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[7]").click()
elif process == '堆存':
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/form/div/div[2]/div[1]/div/input[8]").click()
else:
print("process is wrong")
self.element_Xpath(
"/html/body/div[3]/div/div/div/div/div/div[2]/div/button[1]").click()


1楼2017-03-06 15:26回复