Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a selenium test case from another python file

I am trying to execute a selenium test case from a python file. I know that it can be done using subprocess module of python - but I want to explore the possibility of calling the testcase's functions instead.

This is my code

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()
like image 285
user83969 Avatar asked Apr 13 '26 19:04

user83969


1 Answers

This did it

import chrome_settings_test
import unittest

unittest.main(module=chrome_settings_test)

Thanks to santiycr https://gist.github.com/4274570

like image 192
user83969 Avatar answered Apr 16 '26 07:04

user83969



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!