Monday, February 16, 2015

Python selenium test automation with Nose

Test file details:

from selenium import webdriver
import unittest

class TestUI(unittest.TestCase):
    ''' Test documentation '''

    driver = webdriver.Firefox()

    def test_case1(self):
        self.driver.maximize_window()

    def test_case2(self):
        self.driver.maximize_window()
        self.driver.get("<Web address>")
        self.driver.implicitly_wait(5)
        assert "<Title>" in self.driver.title

    def test_case3(self):
        uname1 = self.driver.find_element_by_id('username')
        pwd = self.driver.find_element_by_id("password")
        login = self.driver.find_element_by_id('loginAction_login_submit')
        uname1.send_keys("admin")
        pwd.send_keys("Password1")
        login.click()
        self.driver.implicitly_wait(5)

    def test_case4(self):
        configmgmt = self.driver.find_element_by_id("configuration")
        configmgmt.click()
        self.driver.implicitly_wait(5)
        mapgrps = self.driver.find_element_by_id("mapings")
        mapgrps.click()
        self.driver.switch_to_frame(self.driver.find_element_by_tag_name("iframe"))
        self.driver.implicitly_wait(5)

    def test_case5(self):
        mapping = self.driver.find_element_by_xpath("//form/table[2]/tbody/tr[2]/td/table/tbody/tr/td/div/table/tbody/tr/td/table/tbody/tr[2]/td[1]/input")
        if mapping.is_selected():
            pass
        else:
            mapping.click()
            self.driver.implicitly_wait(5)
            submit = self.driver.find_element_by_id("Operatorsubmit")
            submit.click()

    def test_case6(self):
        self.driver.switch_to_default_content()
        logout = self.driver.find_element_by_css_selector('font')
        logout.click()
        self.driver.implicitly_wait(3)
        self.driver.close()



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

How to execute using nose framework?


No comments:

Post a Comment