Monday, February 16, 2015

Nose framework test discovery

To discovers test by Nose, structure the folders as

Module
    --- test_script.1py
    -- -Test_Module2
             --- test_script1.py
          

Command to exeute all cases

 




--with-html for html output.


HTML output report will be generated for each test files.


Python selenium Nose test execution : HTML Report

To generate test execution status in HTML format in NOSE.

Step 1. Install 'nose-htmloutput' using pip command












Step 2: Once html output is installed, Execute the testscript with option "--with-html"


Thats it.

Step 3: HTML file output

















Step 4: HTMLfile output for failed cases




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?


Saturday, February 14, 2015

Python: Reverse order of a number

Reverse order of a number

def reverse(n):
    total = ""
    while n > 0:
        a = n % 10
        n//= 10
        total += str(a)
    return total

print reverse(144)

Friday, February 13, 2015

Fibonacci number in python

def fibonnaci(n):
    ''' Identifying fibonnoaci value for the given number n '''
    if n <= 1:
        return n
    else:
        return fibonnaci(n - 1) + fibonnaci(n - 2)

number = int(raw_input('Enter the number of terms: '))
series = []
for i in range(number):
    series.append(fibonnaci(i))
for serie in series[::-1]:
    print serie

Ascending orders of a list

def element(x):
    first_element = x[0]
    for i in range(0, len(x)):
        if first_element <= x[i]:
            pass
        else:
            first_element = x[i]
    return first_element

def ascending(y):
    new_list = []
    old_list = y
    for i in range(0,len(y)):
        small = element(y)
        new_list.append(small)
        old_list.remove(small)
    return new_list[-2]

#print ascending([5,25,41,8,-35,-63,-0.25,21])

Program 2:

__author__ = 'valli_000'

def bubblesortdescending(list):
    length = len(list)
    count = length-1
    while count > 0:
        for i in range(length-1):
            if list[i] <= list[i+1]:
                temp = list[i]
                list[i] = list[i+1]
                list[i+1]=temp
                #print list
            else:
                pass
        count= count - 1
    return list

def bubblesortascending(list):
    length = len(list)
    count = length-1
    while count > 0:
        for i in range(length-1):
            if list[i] <= list[i+1]:
                pass
                #print list
            else:
                temp = list[i]
                list[i] = list[i+1]
                list[i+1]=temp
        count= count - 1
    return list



print bubblesortdescending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])
print bubblesortascending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])



Sunday, February 8, 2015

Python Selenium Notes

Python Selenium notes:

Case 1:
Sometimes identified the element using xpath works fine with the selenium IDE, but not with the webdriver ( or via python script)

Solution:
Then its not the problem of the xpath element.

The problem with the webpage framing.We should move to the respective frame first and then use the xpath.

Eg;
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
driver.find_element_by_xpath("ENTER THE XPATH HERE")
-----------------------------------------------------------------------------------------------------
Case 2:
After case 1, how to back to the default frame to access the other elements?

Solution:
driver.switch_to_default_content()
-------------------------------------------------------------------------------------------------------
Case 3:
Mouse over command in python

Solution:

product = driver.find_element_by_link_text("Products")
Hover = ActionChains(driver).move_to_element(product)
Hover.perform()
-------------------------------------------------------------------------------------------------------
Case 4:
Access variable of one function from another function in a class without using __init__ method

Solution with example:

class Testclass():
    #a = "vallinayagam"
 
    def method_one(self):
        a = "valli"
        return a
     

    def method_two(self):
        print self.method_one()
     
ba = Testclass()
ba.method_two()
------------------------------------------------------------------------------------------------------
Case 5:
Xpath filter commands:

For below HTML,






in the <td, we can access the values for class, data-year, data-month using below command

1. First identify the xpath  by rightclick -> Copy XML and filter t using "data-month]

 xpath path  =//div[5]/div/table/tbody/tr/td[5]
 Filter = [@data-month='2']

To locate element using xpath = "xpath=//div[5]/div/table/tbody/tr/td[5][@data-month='2']"

Case 6:
How to select a value from dropdown box?








Solution:
Step 1: Identify the ID and value from the options tag. you want?

code:
set = driver.find_element_by_id('ctl00_ctl00_body_PrintContent_IWOVID_item_1_ddlCountries')

for option in set.find_elements_by_tag_name('option'):
if option.text == 'India':
option.click()
break