从另一个python-fi执行selenium测试用例

2024-04-25 13:10:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从python文件执行selenium测试用例。 我知道可以使用python的subprocess模块来实现这一点,但是我想探讨调用testcase函数的可能性。在

这是我的密码

chrome_设置_测试.py在

from selenium import w ebdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import os, shutil, sys

from selenium.webdriver.chrome.options import Options
from selenium import webdriver

class SeleniumException(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)


    #self.driver = nested_selenium.driver
        self.base_url = "https://www.google.co.in/"
        self.verificationErrors = []

    def test_selenium_exception(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("gbqfq").clear()
        driver.find_element_by_id("gbqfq").send_keys("Check this out")

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

硒_财务执行.py在

^{pr2}$

Tags: frompyimportselfbydefdriverselenium
2条回答

它做到了

import chrome_settings_test
import unittest

unittest.main(module=chrome_settings_test)

感谢santiycr https://gist.github.com/4274570

如果希望能够直接调用SeleniumException类的方法,可以实例化它。在

import chrome_settings_test

print "going to call"
my_test = chrome_settings_test.SeleniumException()
my_test.setUp()

相关问题 更多 >