51Testing软件测试论坛

标题: 一个类调用另一个类中的方法,为什么只能调用两个 [打印本页]

作者: cq520131517    时间: 2017-4-19 19:07
标题: 一个类调用另一个类中的方法,为什么只能调用两个
  1. # coding:utf-8
  2. from selenium import webdriver
  3. from time import sleep


  4. class RanzhiCommon(object):
  5.     def __init__(self, driver, base_url):
  6.         driver = webdriver.Chrome()
  7.         self.old_driver = driver
  8.         self.base_url = base_url

  9.     def open_page(self, driver):
  10.         driver = self.old_driver
  11.         driver.get(self.base_url)
  12.         sleep(3)

  13.     def log_in(self, account, password):
  14.         driver = self.old_driver
  15.         #用户名
  16.         element_account = driver.find_element_by_name('username')
  17.         element_account.clear()
  18.         element_account.send_keys(account)
  19.         sleep(2)
  20.         #密码
  21.         element_password = driver.find_element_by_id('password')
  22.         element_password.click()
  23.         element_password.send_keys(password)
  24.         driver.find_element_by_xpath('//*[@id="loginForm"]/table/tbody/tr[1]/td[2]/table/tbody/tr/td[2]/table/tbody/tr[13]/td/table/tbody/tr/td[2]/a/b').click()

  25.     def log_out(self):
  26.         driver = self.old_driver
  27.         driver.find_element_by_xpath('//*[@id="menu-shiva_trtms_ground"]/li[1]/a/span').click()
  28.         driver.find_element_by_xpath('//*[@id="menu-frame-system-tools"]/li[5]/a/span/span[1]/span').click()
  29. 这是第二个类
复制代码

作者: cq520131517    时间: 2017-4-19 19:08
import unittest
from selenium import webdriver
from xiaowei0202 import RanzhiCommon


class TestPage(unittest.TestCase):
    Chrome_driver = None
    base_url = None
    common = None

    def setUp(self):
        self.Chrome_driver = webdriver.Chrome
        self.base_url = 'http://10.202.58.46/frame.pvt'
        self.common = RanzhiCommon(self.Chrome_driver, self.base_url)

    def tearDown(self):
        self.common = None

    def test_01_log_in_by_admin(self):
        common = self.common
        common.open_page('')
        common.log_in("217038", "active.123")
作者: cq520131517    时间: 2017-4-19 19:12
这是第一个类
我现在想在
  1. def test_01_log_in_by_admin(self):
  2.         common = self.common
  3.         common.open_page('')
  4.         common.log_in("217038", "active.123")
复制代码
后面加common.log_out(),但是为什么没有提示?而上面的两个方法有提示????
作者: puchonghui    时间: 2017-4-20 08:26
这种问题多半是同步调用搞出来的,你先试试把sleep设长一点看看有没有用。。。。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2