Showing posts with label QC OTA. Show all posts
Showing posts with label QC OTA. Show all posts

13.4.17

Troubleshooting hacks, Jugaad


1.              Guice Provision Error -
Cause - Happens when Surefire plugin is initiated on Maven 3.0.5 (which is too old now). This usually happens on Jenkins/TC when the default settings for Maven are used.
Resolution - Use latest version of Maven and specify the same in Jenkins' Maven Settings too

2.              SurefireBooterException -          
To resolve, add this config in the POM, to set useSystemClassloader to false:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>

3.              Run Maven commands without changing dir –
We don’t need to ‘cd’ to the directory containing the pom every time we want to run a mvn command, we can fire the mvn command from anywhere as long as we give the path to the pom like below:
Syntax: mvn –f <fullpath-to-pom> <goals> -D<params>
Sample: mvn –f C:/Automation/keyword/pom.xml test –Dthread1=Test1
It would be good to not have any spaces in the path so as to avoid escape char.
Use / instead of \  in the path.

4.              Invoke CMD via VbScript –
If you want to invoke the CMD utility automatically with certain parameters then use the below snippet:
Set oShell = CreateObject(“WScript.Shell”)
cmndToRun = “mvn –f C:/Automation/keyword/pom.xml test –Dthread1=Test1”
oShell.Run “cmd.exe /k “ & cmndToRun
To keep the CMD window open use /k after cmd.exe or use /c to close it.

5.              StackOverflowError –
Happens due to infinite recursion. For example when a method invokes itself during its execution or where one class object is instantiated under another class recursively. We will not get any compile-time Errors, but at runtime we will get this Error.

6.               Maven Compilation Error - package <name> does not exist
Resolution - Sometimes old or un-used packages are not found after updating versions of some libraries, which causes compilation Errors. Fastest solution is to delete these unwanted packages from Java files.

7.              Log4J package is not getting imported in the classes, hence, not able to initiate logging.
Steps to troubleshoot - A combination of these resolved this, after multiple iterations
·       Tried mvn dependency:resolve - It got successfully downloaded when resolving dependencies via mvn.
·       Delete local repo and re-download all dependencies from scratch - Even after deleting the old local repo, and rebuilding the same from scratch, it does not work
·       'Cleaned' the eclipse project - it resolved all Errors, but still Log4J is not getting imported.
·       Delete '.lastUpdated'  files from local repo
·       For Windows cd (change directory) to <user-directory>\.m2\repository and execute this command:
for /r %i in (*.lastUpdated) do del %i
·       Now update dependencies again.
·       You could also get Errors like: [Could not find artifact org.apache.logging.log4j:log4j:jar:2.6.1 in central (https://repo.maven.apache.org/maven2) -> [Help 1]]
·       Run mvn eclipse:eclipse - This could cause the following Error, visible only on eclipse, not in maven: [The project was not built due to "Resource already exists on disk: '/bddproject/target/classes/log4j.properties'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent]. To resolve it, run mvn clean, as it will delete the target folder, where this Error was. Then go to eclipse and do Project > Clean. Now, all Errors should be resolved.

8.              Get 'failed to load jvm' Error when running eclipse
            Try restarting the machine, it gets resolved sometimes

9.              Even though the default story steps[in myStory] have been implemented, while running the MyStories class, they still come up as @Pending in the results.
Cause - The Pending annotation was already imported by default in the default MySteps class, which was marking all the steps as pending.
Resolution - Delete that import statement for Pending, and re run the test, it worked and all steps were Green/Run/Passed
Also, if now I add a Pending annotation but do not use it, it still runs the remaining steps, as it should run.
 
10.          Getting junk lines being reported in the console with the freemarker log -
Like - "Jul 05, 2016 1:17:56 AM freemarker.log._JDK14LoggerFactory$JDK14Logger info"
If Log4J works, then this is not needed

11.          Run via mvn is Erroring out -
mvn clean install - this command Errors out
Error - [Error] Failed to execute goal org.jbehave:jbehave-maven-plugin:4.0.5:run-stories-as-embeddables (embeddable-stories) on project bddproject: Execution embeddable-stories of goal org.jbehave:jbehave-maven-plugin:4.0.5:run-stories-as-embeddables failed: A required class was missing while executing org.jbehave:jbehave-maven-plugin:4.0.5:run-stories-as-embeddables: org/apache/log4j/Priority

12.          The simple-archetype comes with the default jbehave report template, which needs to be fixed

13.          Even though the M2E plugin is downloaded and installed, it does not show up in eclipse - there is nothing for maven

14.          Getting the following Error while running dependency:resolve command
Error - Failed to collect dependencies at org.jbehave:jbehave-core:jar:4.0.5 -> com.thoughtworks.xstream:xstream:jar:1.4.7:
Cause - Looks like the command to download the dependencies was getting timed out, as it worked well when the internet connection was strong
Resolution - Ran the dependency:resolve command again, and it was successful, without any Errors

15.          Getting the following Error when deleting and re-importing the bdd project
Error - unbound classpath variable 'm2_repo
Cause - Eclipse is not able to locate the path of the local mvn repo
Resolution - The below steps work to solve this issues
·       Open the Eclipse Preferences [Window - Preferences]
·       Go to [Java - Build Path - Classpath Variables]
·       Click New and set its name as M2_REPO
·       Click Folder and select your Maven repository folder. For example, my repository folder is C:/Users/user/.m2/repository
·       Rebuild the Project.

16.            No need to run these commands
mvn compile
mvn clean install
mvn clean

17.          Error - archive for required library cannot be read in eclipse
·       This generally happens when you are importing projects, which has external jars [added via maven POM or via direct import]
·       The first thing to try is delete those external jars and their folders, and then re-import them
·       Then in Eclipse, go to Project > Clean Project [Ensure that Build Automatically is checked]
·       If this does not resolve, then see if the jars got corrupted during copy/import, then replace them with original/valid jars

18.          Avoid having multiple versions of the same jars in the projects - only have the required version and delete the rest.

19.          If you get Errors like 'Source Not found' or 'Attach source', or 'NoClassDefFoundException' it generally means some jar is missing and not there in your build path, so find that jar, and just add it to your build path

20.          Split method in Java has a bug!
·       When we use a split function, ideally, if we don’t specify any limit, it should return all the tokens in the string, but it does not, if you have multiple delimiters in the end with empty tokens. 
·       For example in a | delimited message ("ASDAS|ASDASD|AA||||ASS|||||"), the last empty tokens would be ignored.
·       To fix this use the limit as -1
·       String[] token = sampleMsg.split("\\|" , -1);

21.          Always use string.isEmpty() method to check if the string is empty or not. 
1.    Never use null or any other method. Even if the variable is not a String, convert it to String via toString and then use isEmpty().
2.    Though a lot of people would frown upon this idea, but its simple, effective, and very easy to remember and can be implemented by a rookie in your team
22.          Ensure that you use JDK [and not JRE] in your Project Build Path

23.          Apache POI –
When adding apache poi in the dependency tree ensure to add dependencies for "poi-ooxml" and "poi-ooxml-schemas" as well, as some of the base classes for apache poi use these jars, and otherwise we would not be able to use certain classes like XSSF.

24.          If QCUtils is not working in UFT
·       Try checking the Registry values for this key.
·       'HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTestProfessional\MicTest\QEEE'. 
·       This key had the parameter 'ExternalExecutionSupported', so either set it to Yes or delete it.
 
 
Other Hacks -
  • Error: Could not find PKIX Certificate Path when connecting to Artifactory.
    • Problem: When trying to run any maven commands on windows machines, sometimes we get this error where we are not able to connect to Artifactory or any Central Repo in Enterprise setups. This error will not come on your home computer but its one of the perks of working in a big Co.
    • What its not: This problem is not related to your Artifactory credentials or API Keys, or git or bitbucketor even the maven Settings.XML; although thats what you might be lead to think.
    • Cause: The problem is related to outdated Java Security Certificates or the use of incorrect ones. This happens when the java pkg gets upgraded or the one that you currently have installed does not have the required certificates. So the solution really lies in updating the security certificate file (cacertificates file in jdk dir).
    • Sol 1: Manually find and download the latest certificate and then update the cacertificates file, and then import them via the usual 'keystore' import command that you can easily google. The prob with this approach is that it needs Admin rights to edit the cacertificates file, and you will not get that ever in a big Co - another perk. So this method is DOA.
    • Sol 2: If your jdk package has recently been upgraded, then you might be lucky enough to get the latest java cacertificates files which will hopefully have the correct certificates added, and you will have to re-point your JAVA_HOME and M2_HOME and PATH variables to this new jdk pkg.
      • But that also needs Admin rights, so you will not be able to do that also. Sometimes some Cos have support teams that give you temp Admin rights, which might save the day for you, if not, read on...
      • What you can do is reset the Env Variables like JAVA_HOME and M2_HOME and PATH to new values for the current session via CMD prompt. This will work only till the time this CMD prompt is open, and all changes will be lost when you close it, and you will have to re-do these. The steps are:
        • SET JAVA_HOME=<new path>
        • SET JDK_HOME=<new path>
        • SET PATH=<new path>;%PATH%
        • Remember to append to the PATH variable otherwise it will overwrite and remove all the other values in it.
        • No need to change the variables for Maven
        • This should point your current session to the new jdk pkg folder which has the correct certs file.
    • Sol 3: Create a new folder for JDK pkg where you would have admin rights and then re-point all the variables, including Maven based, to this new folder. This approach would be helpful if you are trying to update the existing certs file with the new certs



14.5.16

SQL Queries for Quality Center Modules

One of the few good things [there are only few] about QC is that all the info is stored in a MSSQL DB, and can be easily accessed via QC OTA, Analysis Modules, etc. Here are a few samples.

A. Notes on some Components of QC Database -
  • RELEASE_CYCLES - this table stores details about the releases created in the Release module.
  • CYCLE - this table stores info about the test sets, and uses CY_ASSIGN_RCYC
  • TESTCYCL - this table stores info about the instances of test runs, status, etc
  • TEST - this table stores info about the test names, test types [manual, automated], designer, etc
 
B. Process to build SQL Queries for different Quality Center modules

All Analysis reports have to be built in the Dashboard >> Analysis module. There are 3 different types of reports that can be built, but Excel is the one we are focusing on right now, since, we can add SQL Queries only to Excel type reports.

Report type - Create a report to get the Status and Count of all the tests present under different Test Sets, for a particular Release Cycle.

Solution Steps -
  • Create a Release Cycle under Management >> Release Module, based on the name of your current release. Eg., 'App_Release2_SIT'.
  • Note down the value of 'Target Cycle ID' field populated in QC - this would get saved as CY_ASSIGN_RCYC field in the QC database, lets assume it as 1005.
  • Create a folder in Test Lab as 'Parent_TL_Folder'. Create another subfolder called SIT under this parent folder, and assign the release cycle, 'App_Release2_SIT' to this folder.
  • If there are 2 different cycles in your plan, one for Functional SIT and one for Regression, then create another cycle for Regression like 'App_Release2_Regression'. Then create a seperate folder for Regression tests, under the same 'Parent_TL_Folder' at the same level as 'SIT' folder, and assign this regression cycle 'App_Release2_Regression' to this folder.
  • Now, create all the different Test Sets for this release under this Test Lab folder. Lets say there are 3 test sets called 'Artifact1' 'Artifact2' 'Artifact3'.
  • Now, pull all your tests under these 3 tet sets, from the Test Plan.
  • Once this all is done, all you need is the 'Target Cycle ID' for both the cycles [SIT and Regression] to query all the tests for the release.

C. Sample Queries -
--------------------------------------------------------------
--Query to get the execution Status and Count for all the tests under a given release cycle

SELECT CYCLE.CY_CYCLE ,
COUNT (*) AS "No of Tests" ,
COUNT (CASE WHEN TESTCYCL.TC_STATUS = 'PASSED' THEN 1 END ) AS 'Passed' ,
COUNT (CASE WHEN TESTCYCL.TC_STATUS = 'FAILED' THEN 1 END ) AS 'Failed' ,
COUNT (CASE WHEN TESTCYCL.TC_STATUS = 'BLOCKED' THEN 1 END ) AS 'Blocked' ,
COUNT (CASE WHEN TESTCYCL.TC_STATUS = 'NO RUN' THEN 1 END ) AS 'No Run' ,
COUNT (CASE WHEN TESTCYCL.TC_STATUS IN ( 'PASSED' , 'FAILED' ) THEN 1 END ) AS 'Executed' ,
COUNT (CASE WHEN TESTCYCL.TC_STATUS = 'NOT COMPLETED' THEN 1 END ) AS 'Partially Executed'
FROM CYCLE
JOIN TESTCYCL ON TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID
--JOIN TEST ON TEST.TS_TEST_ID = TESTCYCL.TC_TEST_ID    --Join with TEST table, can help us pull out TEST_NAME as well for the tests
WHERE 1=1
AND CYCLE.CY_ASSIGN_RCYC = '1005'
--AND CYCLE.CY_CYCLE LIKE 'BRD%'    --filter all the test sets starting with BRD
GROUP BY CYCLE.CY_CYCLE

--------------------------------------------------------------
-- Query to get the Name and ID of the Release Cycle

SELECT RCYC_NAME, RCYC_ID, *
FROM RELEASE_CYCLES
WHERE 1=1
AND RCYC_ID = '1005'

--------------------------------------------------------------
--Query to get Names of all the Test Sets under the chosen Release Cycle

SELECT CY_CYCLE AS "TEST_SET_NAME" , *
FROM CYCLE
WHERE 1=1
AND CY_ASSIGN_RCYC = '1005'
ORDER BY CY_CYCLE

--------------------------------------------------------------
--Query to get Defect related details for a Release

SELECT
BG_BUG_ID AS "DEFET ID" ,
BG_SEVERITY AS "SEVERITY" ,
BG_STATUS AS "STATUS" ,
BG_SUMMARY AS "SUMMARY" ,
BG_PRIORITY AS "PRIORITY" ,
BG_RESPONSIBLE AS "ASSIGNED TO" ,
BG_USER_11 AS "DETECTED BY" ,
BG_DETECTION_DATE AS "DETECTED ON" ,
BG_DEV_COMMENTS AS "COMMENTS"
FROM BUG
WHERE 1=1
AND BG_STATUS NOT IN ('Closed', Deferred' , 'TestReady' )
AND BG_USER_12 = 'SIT ENV'
AND BG_USER_13 = 'App_Release2_SIT'

--------------------------------------------------------------
--Query to get BPT Components for a Test. 
--The below query gets the design steps of the components part of a BPT test in the order they are in the test. Just add the TestID where shown.

SELECT
C.CO_NAME || '[' || BT.BC_CO_INSTANCE || ']',
CS.CS_STEP_NAME ,
CS.CS_DESCRIPTION,
CS.CS_EXPECTED
FROM BPTEST_TO_COMPONENTS BT,
COMPONENT C,
COMPONENT_STEP CS
WHERE 1=1
AND BT.BC_PARENT_ID = <testIDhere>
AND BT.BC_CO_ID = C.CO_ID
AND C.CO_ID = CS.CS_COMPONENT_ID
ORDER BY BT.BC_ORDER, CS.CS_STEP_ORDER

--------------------------------------------------------------

31.5.14

How to work with QC OTA - Example 3 - Function to Run a Query on QC Database

'------------------------------------
' Function Name:         funcRunQueryOnOC
' Description:               This function will run a query on the QC database and then return the recordset containing the results
' Input Parameters:     sQCQuery - The query to be run on the QC database
' Output Parameters:  The QC RecordSet Object
' Author:                      Ashish Jaiswal
'------------------------------------

Function funcRunQueryOnOC(sQCQuery)

    'Getting the QC Connection Object. Refer earlier post about the implementation of this function.
    Set oALMConnObj = funcGetALMConnectionObj (sQCServer, sQCUsername, sQCPassword, sQCDomain, sQCProject)

    'Getting the Command object to run the query
    Set oQCCommand = oALMConnObj.Command

    oQCCommand.CommandText = sQCQuery
    'Sample query: "Select * from Bug where BG_BUG_ID = 9295"

    Set oQCRecordSet = oQCCommand.Execute

    'Now returning the recordset
    Set funcRunQueryOnOC = oQCRecordSet

End Function 
'------------------------------------

How to work with QC OTA - Example 2 - Get a List of All Defects in QC

Code to get a list of all the details for all the defects in QC Defects Module


''Complete path of the file where the info from QC needs to be written
sQCLogFilePath = "C:\Automation\Defects_List.csv"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(sQCLogFilePath)

''Getting the QC Connection Object. Refer earlier post about the implementation of this function
Set oALMConnObj = funcGetALMConnectionObj (sQCServer, sQCUsername, sQCPassword, sQCDomain, sQCProject)

''Getting the Bug Factory object
Set oBugFactory = oALMConnObj.BugFactory

Set oBugList = oBugFactory.NewList("")

oFile.WriteLine("Defect ID" & "," & "Summary")

For Each oBug In oBugList

oFile.WriteLine(oBug.ID & "," & oBug.Summary)
''We can add other fields as: Bug.Status, Bug.Priority, Bug.AssignedTo

Next

Set oFile = Nothing
Set oFSO = Nothing
Set oBugFactory = Nothing
Set oALMConnObj = Nothing

How to work with QC OTA - Example 1 - Get Defect ID and the size of Attachments in each defect

More often than not, we get weird requests, like getting a list of all the defects in QC and the size of attachments for each of them, but thankfully we have QC OTA to help us ease the pain. Use the below code to get a file with Defect ID and the size of all the attachments for them.


''Complete path of the file where the info from QC needs to be written
sQCLogFilePath = "C:\Automation\Attachments_List.csv"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(sQCLogFilePath)

''Getting the QC Connection Object. Refer earlier post about the implementation of this function
Set oALMConnObj = funcGetALMConnectionObj (sQCServer, sQCUsername, sQCPassword, sQCDomain, sQCProject)

''Getting the Bug Factory object
Set oBugFactory = oALMConnObj.BugFactory

''Defining the filters for the Defects
Set oBugFilter = oBugFactory.Filter
oBugFilter.Filter("BG_STATUS") = "Closed"
oBugFilter.Filter("BG_ATTACHMENT") = "Y"
oBugFilter.Filter("BG_DETECTED_BY") = "ASHISH.JAISWAL"

Set oBugList = oBugFilter.NewList

oFile.WriteLine("Defect ID" & "," & "Total Attachment Size")

For Each oBug In oBugList

        Set oBugAttachments = oBug.Attachments
        Set oBugAttachmentList = oBugAttachments.NewList("")

        iTotalAttachmentSize = 0
        For Each oBugAttachment In oBugAttachmentList
            iTotalAttachmentSize = iTotalAttachmentSize + oBugAttachment.FileSize
        Next

        oFile.WriteLine(oBug.ID & "," & iTotalAttachmentSize)

        Set oBugAttachmentList = Nothing
        Set oBugAttachments = Nothing

Next

Set oFile = Nothing
Set oFSO = Nothing
Set oBugFilter = Nothing
Set oBugFactory = Nothing
Set oALMConnObj = Nothing

5.4.14

Connect to ALM-QC via VbS or QTP


You can use the following code to connect to ALM\QC via pure VbScript, without using QTP, even though this code would work from QTP as well.

Prerequisite:
  • ALM\QC should be installed

Code -

'''----------------------------------------------------------------------------------------------------------------------
'' Function Name:            funcGetALMConnectionObj
'' Description:                   This will connect to the ALM\QC server via either pure VbS or QTP
'' Input Parameters:        sQCServer
''                                         sQCUsername
''                                         sQCPassword
''                                         sQCDomain
''                                         sQCProject
'' Output Parameters:     oALMConnObj [The ALM Connection Object]
'' Author:                          Ashish Jaiswal
'''----------------------------------------------------------------------------------------------------------------------
Function funcGetALMConnectionObj (sQCServer, sQCUsername, sQCPassword, sQCDomain, sQCProject)

    ''Defining the Parent QC OTA Object
    Set oALMConnObj = CreateObject("TDAPIOLE80.TDConnection")

    ''Initiating the connection to the QC Server
    oALMConnObj.InitConnectionEx sQCServer

    ''Logging in
    oALMConnObj.Login sQCUsername, sQCPassword

    ''Connecting to the required project and domain
    oALMConnObj.Connect sQCDomain, sQCProject

    ''Returning the object
    Set funcGetALMConnectionObj = oALMConnObj

End Function
'''----------------------------------------------------------------------------------------------------------------------

Usage:

''Defining the connection parameters for QC
sQCServer = "http://ealm11.anyorg.net/qcbin/"
sQCUsername = "username"
sQCPassword = "password"
sQCDomain = "domain"
sQCProject = "projectname"

Set oALMConnObj = funcGetALMConnectionObj (sQCServer, sQCUsername, sQCPassword, sQCDomain, sQCProject)

''Proceeding ahead only if connected
If oALMConnObj.Connected Then

    MsgBox "Connected to QC!"
    MsgBox oALMConnObj.ProjectName

Else

    MsgBox "Not connected to QC"

End If
'''----------------------------------------------------------------------------------------------------------------------

Common troubleshooting measures -

  • Register the OTAClient.dl
    • For this put the OTAClient.dll in the "C:\Windows\System32" drive, if its not already there
    • Run the following command to [re]register the dll from the Run window
                      RegSvr32 "C:\Windows\System32\OTAClient.dll"

  • If you are getting an error something like 'ActiveX can't create object - TDConnection' then try running the connection code by putting in a .vbs file, from the Run window as follows, via the WScript.exe -
           C:\Windows\SysWOW64\wscript.exe "C:\Automation\QC-Connection.vbs"