Selenium

Selenium

Check my New Blog: http://kanoki.org

Running chrome selenium driver

package mypackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver; 

public class myclass {

	public static void main(String[] args) {

		System.setProperty("webdriver.chrome.driver", "C:\\selenium-java-2.35.0\\chromedriver_win32_2.2\\chromedriver.exe");

		 WebDriver driver = new ChromeDriver();
         driver.get("http://www.google.com");
	}

}
Project Euler

Solution Project Euler – Problem 34: Digit Factorials

# 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
# Find the sum of all numbers which are equal to the sum of the factorial of their digits.
# Note: as 1! = 1 and 2! = 2 are not sums they are not included.

def factorial(x):
  y=int(x)
  n=1
  fact=1
  while n < y:
    fact=fact*(n+1)
    n=n+1
  return fact

sum1 = 0
for j in range(10,100000):
  str1 = str(j)
  length = len(str1)
  sum = 0
  for i in range(1,length+1):
    sum = sum + factorial(str1[i-1])
  if sum == j:
    sum1 = sum1 + sum
print sum1
OTA API: Quality Center

Excel Utility: Quality Center: OTA API

Attached is the utility…Just download enter the details and get started…tested and verified on Quality Center 10.0…

original_system_testing_report_generator – Copy


Module 1:

Dim req As req
 
Public Sub ImportQC_Click()

If check_req_fields = True Then
    Connect_QC_Import
Else
    Exit Sub
End If

End Sub


Public Function check_req_fields() As Boolean

fld_flag = False


Set sht = Worksheets(ActiveSheet.Name)
TD_Path = Trim(sht.Cells(1, 2))
TD_User = Trim(sht.Cells(2, 2))
TD_Pwd = Trim(sht.Cells(3, 2))
TD_Domain = Trim(sht.Cells(4, 2))
TD_Prjt = Trim(sht.Cells(5, 2))
TD_Fldr = Trim(sht.Cells(6, 2))
TD_Tset = Trim(sht.Cells(7, 2))
ATT_path = Trim(sht.Cells(8, 2))

If TD_Path = "" Then
    MsgBox "Please Enter TD URL"
ElseIf TD_User = "" Then
    MsgBox "Please Enter User ID"
Else
    fld_flag = True
End If

check_req_fields = fld_flag

End Function

Public Sub Delete_Existing()
Set sht = Worksheets(ActiveSheet.Name)

sht.Range("A13:P65536").UnMerge
lstrow = sht.Cells.SpecialCells(xlCellTypeLastCell).Row

If lstrow = 12 Then
lstrow = 13
End If

sht.Range("A13:P" & lstrow).Delete


sht.Cells(2, 7) = ""
    sht.Cells(2, 8) = ""
    sht.Cells(2, 9) = ""
    sht.Cells(4, 9) = ""
    sht.Cells(5, 9) = ""
    sht.Cells(6, 9) = ""
    sht.Cells(7, 9) = ""
End Sub



Public Sub Connect_QC_Import(TD_Fldr)



check_req_fields


Set tdc = New TDConnection
Set fso = New FileSystemObject

Set sht = Worksheets(ActiveSheet.Name)

Excel.Application.DisplayAlerts = False

I = sht.Cells(Rows.Count, 1).End(xlUp).Row + 1
On Error GoTo err_msg
    

    tdc.InitConnectionEx TD_Path
    tdc.ConnectProjectEx TD_Domain, TD_Prjt, TD_User, TD_Pwd
    
    Set tsTreeMgr = tdc.TreeManager
    
    Set TestF = tdc.TestFactory
    
    tspath = "^Subject" & TD_Fldr & "^"

    
    
    Set bfilter = TestF.Filter
    bfilter.Filter("TS_SUBJECT") = tspath
    Set TestList = bfilter.NewList
    
    
    For Each test In TestList
                  
        TS_Start = I
        
        NodePath = tsTreeMgr.NodePath(test.Field("TS_SUBJECT").NodeID)
        
        
        sht.Cells(I, 1) = StripTags(test.Name)
        
          
        Set CVList = test.GetCoverList
          
        For Each ID In CVList
          If Trim(sht.Cells(I, 3)) = "" Then
        
          Else
        
          End If
        Next
        
        
        
        Set DStpF = test.DesignStepFactory
        Set DStpL = DStpF.NewList("")
        Set rt = test.LastRun

        
        If rt Is Nothing Then
               
            For Each DStp In DStpL
                
                

                I = I + 1
            Next
            
            If DStpL.Count = 0 Then
                I = I + 1
            End If
            
        Else
            
           
            sht.Cells(I, 2) = rt.Field("RN_TESTER_NAME")
            RN_DATE_TIME = rt.Field("RN_EXECUTION_DATE") & " " & rt.Field("RN_EXECUTION_TIME")

sht.Cells(I, 3) = Format(RN_DATE_TIME, "DD/MM/YYYY HH:MM AM/PM")

 
            Set stf = rt.StepFactory
            Set sts = stf.NewList("")

             sht.Cells(I, 4) = rt.Status
            
            For Each st In sts
                



                I = I + 1
            
            Next
            
            If sts.Count = 0 Then
                I = I + 1
            End If
            
        End If
        
        TS_Last = I - 1

        COL_FMT = "A,B,C,D,E,K,L,M,N,O,P"
        col_fmt_arr = Split(COL_FMT, ",")
        
        For J = 0 To UBound(col_fmt_arr)
            COL = col_fmt_arr(J)
            
        Next
        
           

    Next
                                 

sht.Rows.AutoFit

lst_rw = TS_Last




    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlTop
    End With



Replace_Esc_Seq

tdc.Logout
Set tdc = Nothing

Exit Sub

err_msg:
MsgBox Err.Description

If tdc.Connected = True Then
    tdc.DisconnectProject
    Set tdc = Nothing
End If

'DeleteRowsThatLookEmptyinColA
End Sub


Public Sub Replace_Esc_Seq()

sht.Cells.Replace "&lt;", "<"
sht.Cells.Replace "&gt;", ">"
sht.Cells.Replace "&amp;", "&"
sht.Cells.Replace "&quot;", Chr(34)

End Sub

Public Sub UpdateQC_Click()

If check_req_fields = True Then
    Connect_QC_Export
Else
    Exit Sub
End If

End Sub



Sub DeleteRowsThatLookEmptyinColAFeed()

Dim wsQ As Worksheet

Set wsQ = Worksheets("Master Sheet")

    For I = wsQ.Cells(Rows.Count, 1).End(xlUp).Row To 13 Step -1
        If wsQ.Cells(I, 1) = "" Then wsQ.Cells(I, 1).EntireRow.Delete
    Next I
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic



End Sub

Sub main()
V = 0
I = 0
N = 0


Set wsA = Worksheets("Test Plan Folder Path")
Set wsB = Worksheets("Master Sheet")
Dim wsQ As Worksheet
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = wsA.UsedRange.Rows
End If


For R = Rng.Rows.Count To 1 Step -1
TD_Fldr = wsA.Cells(R, 1)
Connect_QC_Import (TD_Fldr)
Next R

DeleteRowsThatLookEmptyinColAFeed

For J = wsB.Cells(Rows.Count, 1).End(xlUp).Row To 13 Step -1
        If wsB.Cells(J, 4) = "Failed" Then V = V + 1
        If wsB.Cells(J, 4) = "Passed" Then I = I + 1
        If wsB.Cells(J, 4) = "Not Completed" Then N = N + 1

Next J
    
    wsB.Cells(2, 7) = I
    wsB.Cells(2, 8) = V
    wsB.Cells(2, 9) = N
    


End Sub


Module 2:

Public fso As FileSystemObject
Public folder As folder
Public folder1 As folder
Public file As file

Public tdc As New TDConnection
Public cmd As Command
Public rst As Recordset

Public TestSetF As TestSetFactory
Public TestSetList As List
Public ts As TestSet

Public tstf As TSTestFactory
Public tsts As List
Public tst As TSTest

Public stf As StepFactory
Public sts As List
Public st As Step

Public runf As RunFactory
Public rs As List
Public rt As Run

Public bugf As BugFactory
Public bugl As List
Public bug As bug

Public attf As AttachmentFactory
Public att As Attachment

Public bfilter As TDFilter

Public Dpath, QAVPath, RPTPath, QRFlag

Public sht As Excel.Worksheet
Public sht1 As Excel.Worksheet


Public TestF As TestFactory
Public TestList As List
Public test As test

Public DStpF As DesignStepFactory
Public DStp As DesignStep
Public DStpL As List

Public tsTreeMgr As TreeManager
Public Trees As List
Public tsSubjectNode As SubjectNode


Public TD_Path, TD_User, TD_Pwd, TD_Domain, TD_Prjt, TD_Fldr, TD_Tset, ATT_path

Public Function StripTags(HTMLString)
Dim objRegEx As RegExp

Set objRegEx = New RegExp

With objRegEx
.Pattern = "<[^>]+>"
.IgnoreCase = True
.Global = True
End With

StripTags = objRegEx.Replace(HTMLString, "")
End Function


Module 3:
Sub Graph()
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xl3DPieExploded
    ActiveChart.ApplyLayout (2)
    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("H11:K12")
End Sub