tieto interview

Upload: atulsinghchouhan

Post on 02-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 TIETO Interview

    1/6

    1. How to compare 2 str case censitive

    using strcomp(str1,str2,booleanvalue), we can compare two

    strings

    e.g: strcomp("abcd","ABCD",0) results 0 - avoids case

    sensitive

    strcomp("abcd","ABCD",1) results -1 follows case sensitive

    2.

    swap two variables by using call by reference in vbscript

    how to swap two numbers by using a function in vb 6

    command1 _ click()dim a,b as integer

    a=10

    b=20

    swap a,b(error here type mis match)

    text1.text=a

    text2.text=b

    end sub

    Public Function swap(byref x As Integer, ByRef y As Integer)

    Dim temp As Integer

    temp = x

    x = y

    y = temp

    End Function

    3. how to arrange interger in ascending order

    a=array(1,5,6,3,10,8,2)

    For i=0 to 6

    For j=0 to 6

    If a(i)

  • 8/11/2019 TIETO Interview

    2/6

    End If

    Next

    Next

    For i=0 to 6

    msgbox a(i)

    Next

    4. how to add intergers array

    Arr[10] = (1,2,3,4,5,6,7,8,9,0)

    Dim arrNumbers(10)

    tally = 0

    For counter =1 To 10

    arrNumbers(counter) = counter

    sum = sum + counter

    Next

    WScript.Echo sum

    5.Find all the files in a given folder using For Each Loop'Get instance of all the files in a given folderSetoFSO = CreateObject("Scripting.FileSystemObject")SetoFolder = oFSO.GetFolder("D:\")SetoFiles = oFolder.Files

    'Loop through all the files in 'D:\' DriveForEachfile in oFiles

    'Display the name of the filemsgbox file.Name

    Next

    6. Find whether given year is a leap year

  • 8/11/2019 TIETO Interview

    3/6

    1. '1st Method2.3. 'The rules for leap year:4. '1. Leap Year is divisible by 4 (This is mandotory Rule)5. '2. Leap Year is not divisible by 100 (Optional)6. '3. Leap Year divisble by 400 (Optional)7.

    8. DimoYear9.10. oYear=199611.12. If((oYear Mod4 = 0) And(oYear Mod100 0) Or(oYear Mod400 = 0)) then13. print "Year "&oYear&" is a Leap Year"14. else15. print "Year "&oYear&" is not a Leap Year"16. EndIf17.18.19. '45. 2nd Method20. ' Checking 29 days for February month in specified year21. DimoYear22. DimtmpDate

    23.24. oYear=199625. tmpDate = "1/31/"& oYear26. DaysinFebMonth = DateAdd("m", 1, tmpDate)27.28. If day(DaysinFebMonth )=29 then29. print "Year "&oYear&" is a Leap Year"30. else31. print "Year "&oYear&" is not a Leap Year"32. EndIf

    7. Exception Handling

    a) Recovery Scenario - When you are not sure of the error and might occur anytime in the script

    execution. Some of the good areas for Recovery Scenario can be handling 'Object not Found' and then

    Failing your test, so that you can proceed to the next test case.

    b) On Error Resume Next - This is used to avoid any errors at runtime during execution, so as to prevent

    'General Run Error' shown by QTP thus stopping script execution. Also, you can catch the error using If

    err.Number0 and performing the required steps.

    c) A good practice is to use .Exist statements when you want to check on an object (something you think

    might take time to be visible, or is necessary for that test case to continue ahead)

    d) CheckProperty and WaitProperty on an object. CheckProperty is to provide a CHECK on an object,

    while WAITProperty is to provide TIME for a specific property of the object to be TRUE. WaitPropertymight not always confirm if the object exists or not.

    8. How to connect to database.

    QTP Scripts for connecting to MS Access:

  • 8/11/2019 TIETO Interview

    4/6

    OptionExplicitDimcon,rs

    Setcon=createobject("adodb.connection")Setrs=createobject("adodb.recordset")

    con.open "Driver={Microsoft Access Driver

    (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;"

    rs.open "select * from emp",con

    Dowhilenotrs.eofVbWindow("Form1").VbEdit("val1").Setrs.fields("v1")VbWindow("Form1").VbEdit("val2").Setrs.fields("v2")VbWindow("Form1").VbButton("ADD").Clickrs.movenextLoop

    'Release objects'Release objectsSetrs= nothingSetcon= nothing

    Note:The database we are using here is MS Access.Before running this script create a table in MS Acess.In theabove script I used table called "emp" and column 'names as "v1" and "v2". "d:testdata.mdb" is path of the tablewhich we created. The main use of this script is to use testdata of table(which is in ' database) in the application. Inthe above script we are passing values from database to Textboxes in Windows Application.

    QTP Script for connecting to sqlserver:

    OptionExplicitDimcon,rs

    Setcon=createobject("adodb.connection")Setrs=createobject("adodb.recordset")

    con.open"Driver={SQLServer};server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs"rs.open "select * from emp",con

    Dowhilenotrs.eofVbWindow("Form1").VbEdit("val1").Setrs.fields("v1")VbWindow("Form1").VbEdit("val2").Setrs.fields("v2")VbWindow("Form1").VbButton("ADD").Clickrs.movenextLoop

    'Release objects'Release objects

    Setrs= nothingSetcon= nothing

    QTP Script for connecting to oracle:

    OptionExplicitDimcon,rs

  • 8/11/2019 TIETO Interview

    5/6

    Setcon=createobject("adodb.connection")Setrs=createobject("adodb.recordset")

    con.open "Driver={Microsoft ODBC for Oracle};Server=QTPWorld;Uid=your_username;Pwd=your_password;"rs.open "select * from emp",con

    Dowhilenotrs.eofVbWindow("Form1").VbEdit("val1").Setrs.fields("v1")VbWindow("Form1").VbEdit("val2").Setrs.fields("v2")VbWindow("Form1").VbButton("ADD").Clickrs.movenextLoop

    'Release objectsSetrs= nothingSetcon= nothing

    QTP Script for connecting to MySQL:

    OptionExplicitDimcon,rs

    Setcon=createobject("adodb.connection")Setrs=createobject("adodb.recordset")

    con.open"Driver={MySQL ODBC 3.51Driver};Server=localhost;Database=myDB;User=Uname;Password=Pwd;Option=3;"rs.open "select * from emp",con

    Dowhilenotrs.eofVbWindow("Form1").VbEdit("val1").Setrs.fields("v1")VbWindow("Form1").VbEdit("val2").Setrs.fields("v2")VbWindow("Form1").VbButton("ADD").Clickrs.movenext

    Loop

    'Release objectsSetrs= nothingSetcon= nothing

    QTP Script for connecting to Excel:

    OptionExplicitDimcon,rs

    Setcon=createobject("adodb.connection")

    Setrs=createobject("adodb.recordset")

    con.open"DRIVER={Microsoft Excel Driver (*.xls)};DBQ=C:\TestStatus.xls;Readonly=True"rs.open"SELECT count(*) FROM [Status$] where Status = 'Failed' ",con

    Msgbox rs(0)

    'Release objectsSetrs= nothingSetcon= nothing

  • 8/11/2019 TIETO Interview

    6/6

    QTP Script for connecting to Sybase:

    OptionExplicitDimcon,rs

    Setcon=createobject("adodb.connection")

    Setrs=createobject("adodb.recordset")

    ' Open a session to the databasecon.open"Driver={SYBASE SYSTEM11};Srvr=myServerAddress;Uid=Uname;Pwd=Pwd;Database=myDataBase;"rs.open"select * from emp",con

    Dowhilenotrs.eofVbWindow("Form1").VbEdit("val1").Setrs.fields("v1")VbWindow("Form1").VbEdit("val2").Setrs.fields("v2")VbWindow("Form1").VbButton("ADD").Clickrs.movenextLoop

    'Release objects

    Setrs= nothingSetcon= nothing