Sunday, 6 December 2015

ssh db connectivity

manual steps:
login forticlient

putty prodip port 2022
ssh ip2
redirects to mysql ip3

with SSHTunnelForwarder(
         ('ip1', 2022),
         ssh_password="user1",
         ssh_username="pwd1",
         remote_bind_address=('ip3', 3306)) as server:
            db = MySQLdb.connect(host='127.0.0.1',
                       port=server.local_bind_port,
                       user='sql_user',
                       passwd='sql pwd',
                       db='sql db')
            with db:
                cur = db.cursor()

Uncertain alert

 try:
            WebDriverWait(self.driver, 5).until(EC.alert_is_present(),
                                   'Timed out waiting for PA creation ' +
                                   'confirmation popup to appear.')

            alert = self.driver.switch_to_alert()
            alert.accept()
            print "alert accepted"
        except TimeoutException:
            print "no alert"

Authenticate during redirection

autoit.win_wait_active("Authentication Required",20)     ie window name is Authentication Required
 autoit.send("username{TAB}password{TAB}{ENTER}")

Thursday, 3 December 2015

Authentication at website level

self.driver.get("https://username:password@abcd.html")

Writing to blinking inputbox

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

actions = ActionChains(self.driver)
        actions.send_keys('dummylogin')
        actions.perform()

Current URL

b=self.driver.current_url

DB connection

db = MySQLdb.connect(host="205.23.1.45",user="testuser",db="nameofdb",port=3306,passwd="pwd")
        with db:
            cur = db.cursor()
               cur.execute("select * from abc where def=%s",order_no)
            rows = cur.fetchone()
            my_result=rows[0]
            self.assertEqual('101',str(rows[1]) )

Alert

alert = self.driver.switch_to.alert
alert.accept()

Functions outside test

def fill_data_1(self):
    a = self.driver.find_element_by_id('visa')
    a.click()

class SprintTests(unittest.TestCase):
   
    def setUp(self):
       
        self.driver = webdriver.Firefox()
        self.driver.get("http://abcd.html")
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
       
    def test_Amount_Orderid_CardDetails_checks(self):
            a = self.driver.find_element_by_xpath("/html/body/div/div/a")
        a.click()
        fill_data_1(self)

Automation Framework

htmlreport.py
************************************************************************
import unittest
import HTMLTestRunner
import os
from tests import SprintTests

dir = os.getcwd()

search_tests = unittest.TestLoader().loadTestsFromTestCase(SprintTests)

smoke_tests = unittest.TestSuite([search_tests])

outfile = open(dir + "\TestReport_Feature.html", "w")

runner = HTMLTestRunner.HTMLTestRunner(
    stream=outfile,
    title='Test Report',
    description='Feature Sanity'
    )

runner.run(smoke_tests)
*************************************************************************

tests.py

*************************************************************************
from random import randint
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from sshtunnel import SSHTunnelForwarder
import MySQLdb
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import autoit
                                                       
class SprintTests(unittest.TestCase):
   
    def setUp(self):

       
        self.driver = webdriver.Firefox()
        self.driver.get("https://abcd.html")
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
       
       
    def test_Amount_Orderid_CardDetails_checks(self):
        ## amount -ive
        #self.driver.get("https://abc.html")
        print "Sub test: Amount negative"
       
    def tearDown(self):
              self.driver.quit()
      
       
if __name__ == '__main__':
    unittest.main(verbosity=2)
*************************************************************************