码迷,mamicode.com
首页 > 编程语言 > 详细

Functional testing - python, selenium and django

时间:2016-06-12 18:40:54      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

Functional testing  - python selenium django - Source Code :

from selenium import webdriver
from selenium.webdriver.common.by import By

from django.test import LiveServerTestCase

class Browser():  #(Run more than one testcases on one browser)
  browser = None
  def __new__(cls):
    Browser.browser = Browser.browser or webdriver.Firefox()
    return Browser.browser

class Base(LiveServerTestCase):
  def setUp(self):
    self.browser = Browser()
    self.browser.maximize_window()
    self.browser.implicitly_wait(10)
    self.flag_close_browser = None
    self.browser.get(self.live_server_url)

  def tearDown(self):
    if self.flag_close_browser == 1:
      self.browser.quit()

  def login(self, user_name, password):
    self.find_element(By.NAME, ‘user_name‘).send_keys(user_name)
    self.find_element(By.NAME, ‘pwd‘).send_keys(password)
    self.find_element(By.TAG_NAME, ‘button‘).submit()
  

  def find_element(self, find_type, element):
    obj = self.browser.find_element(find_type, element)
    if obj.get_attribute(‘type‘) == ‘text‘ and obj.is_displayed():
      obj.clear()
    return obj

  def find_elements(self, find_type, element):
    obj_list = self.browser.find_elements(find_type, element)
    for obj in obj_list:
      if obj.get_attribute(‘type‘) == ‘text‘ and obj.is_displayed():
        obj.clear()
    return obj_list

  

 

Functional testing - python, selenium and django

标签:

原文地址:http://www.cnblogs.com/Vena/p/5578343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!