3

Python ファイルからセレン テスト ケースを実行しようとしています。Pythonのサブプロセスモジュールを使用して実行できることは知っていますが、代わりにテストケースの関数を呼び出す可能性を探りたいです。

これは私のコードです

chrome_settings_test.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()

selenium_fnexec.py

import chrome_settings_test

print "going to call"
chrome_settings_test.unittest.main() #or
#chrome_settings_test.unittest.setUp()
4

2 に答える 2

5

これでできた

import chrome_settings_test
import unittest

unittest.main(module=chrome_settings_test)

santiycr に感謝https://gist.github.com/4274570

于 2012-12-13T06:55:52.223 に答える
0

メソッドを直接呼び出せるようにしたい場合は、SeleniumException クラスをインスタンス化できます。

import chrome_settings_test

print "going to call"
my_test = chrome_settings_test.SeleniumException()
my_test.setUp()
于 2012-12-13T05:35:49.697 に答える