How to add parameters to test cases in Test Plan using Java? - java

I've tried various things and googled multiple hours but couldn't find a solution to my problem.
I'm using the Quality Center OTA API via Com4j to let my programm communicate with QC.
It works pretty good, but now I've stumbed upon this problem:
I want to add new parameters to a test case in "Test Plan" using my programm.
If I used VB it would work somehow like this:
Dim supportParamTest As ISupportTestParameters
Set supportParamTest = TDConnection.TestFactory.Item(5)
Set testParamsFactory = supportParamTest.TestParameterFactory
Set parameter = testParamsFactory.AddItem(Null)
parameter.Name = name
parameter.Description = desc
parameter.Post
Set AddTestParameter = parameter
The important part is the call of AddItem() on the TestParameterFactory. It adds and returns a parameter that you then can give a name and description. In VB the AddItem-method is given Null as argument.
Using Java looks similar at first:
First I establish the connection and get the TestFactory (and the list of test cases).
QcConnect qc = new QcConnect(server, login, password, domain, project);
ITDConnection qcConnection = qc.getConnection();
ITestFactory qcTestFactory = qcConnection.testFactory().queryInterface(ITestFactory.class);
IList qcTestList = qcTestFactory.newList("");
qcTestList contains all tests from Test Plan.
ITest test = qcTestList.item(1);
ISupportTestParameters testParam = test.queryInterface(ISupportTestParameters.class);
ITestParameterFactory paramFac = testParam.testParameterFactory().queryInterface(ITestParameterFactory.class);
No problem so far. All the "casts" are successful.
Now I want to call the addItem-method on the TestParameterFactory, just like in VB.
Com4jObject com = paramFac.addItem(null);
This doesn't work. The addItem()-method always returns null. I've tried various arguments like a random String, a random Integer, the test case's ID, etc. Nothing works.
How do I use this method correctly in Java?
Or in general: How do I add parameters to existing test cases in Test Plan using Java?
Quick note: Adding test cases to Test Plan works very similar to adding parameters to this test cases. You also use a factory and a addItem-method. In VB you give null as parameter, but in Java you use a String (that's interpreted as the name of the test). But as I said, that does not work in here.

I have finally found the answer to this:
Com4jObject obj = iTestParameterFactory.addItem(new Variant(Variant.Type.VT_NULL));
iTestParameter = obj.queryInterface(ITestParameter.class);
iTestParameter.name("AAB");
iTestParameter.defaultValue("BBB");
iTestParameter.description("CCC");
iTestParameter.post();
Regards.

What you want to pass to AddItem is DBNull and not null.
In VB it's the same, but in Java & .NET it's not.
Not sure how DBNull is exposed using Com4J.
Read more about this at this site.

//C# code snippet -> You have to use DBNull.Value instead of null
//Add new parameter and assign values
TestParameter newParam =(TestParameter)tParamFactory.AddItem(DBNull.Value);
newParam.Name = "ParamNew";
newParam.DefaultValue = "DefaultValue";
newParam.Description = "AnyDesc";
newParam.Post();

Related

Is there a way to set a test variable in Java using Robot Framework?

I am trying to call the BuiltIN keyword 'Set Test Variable' in java. The reason being is that I want to declare some variables that are read in from the test data.
I have searched and tried many times without success. I have something like:
Selenium2Library selenium2Library = Selenium2Library.getLibraryInstances();
String[] test = new String[1];
test[0] = "hello";
selenium2Library.runKeyword("Log", test);
This gives a null pointer exception error. I get the same error when instead of Log I use Set Test Variable, which is what I want. Any help is much appreciated.

UFT/QTP: Count child objects in Java Internal Frame

I need to compare a string with all values of my text fields that are inside in a Java Internal Frame.
I already tried to use this code:
Dim getElement
Set getElement = Description.Create
getElement("class description").value = "text box"
'I tried different class names: "OracleTextField", "JavaEdit"
'getElement("micclass").value = "OracleTextField"
'getElement("micclass").value = "JavaEdit"
Set obj = Browser("xxxx").JavaApplet("Main").JavaInternalFrame("yyyy").ChildObjects(getElement)
total = obj.Count
' For loop goes here
total returns 0 all the time.
Can you tell me what I'm doing wrong?
If you need something more let me know.
I tried the following line and it works. Now i have total number of text fields available in Java internal frame.
getElement("to_class").value = "JavaEdit"
Following QTP documentation didn't help, but if you check your object properties inside your Object Repository you'll find all properties of each object. Instead of "micclass" try to use your property name. Mine was "to_class" with value "JavaEdit".
QTP Documentation explains why we should use "micclass" and differences between "micclass" and "Class Name". However none of them worked for me. I used "to_class" property and it works fine!
I'm working with UFT v12.02

JRules Studio - Display values of IN_OUT parameters while testing

I'm using JRules Studio to develop some extremely simple rules. The rules populate an IN_OUT parameter. When the test finishes, is there a way of interrogating the values in the IN_OUT object?
Initially I'd like to interrogate it in the debugger, but any other ideas would be welcomed.
I am not sure to understand the question:
Your JAVA code is like this:
IlrSessionFactory factory = new IlrJ2SESessionFactory();
IlrStatelessSession session = factory.createStatelessSession();
IlrSessionRequest sessionRequest = factory.createRequest();
sessionRequest.setRulesetPath(“/RuleAppName/rulesetName”);
sessionRequest.setTraceEnabled(true);
sessionRequest.getTraceFilter().setInfoAllFilters(true);
Map inputParameters = new HashMap ();
Report in_report = new Report(); // no-arg constructor
// ... populate the Object ...
inputParameters.put("report", in_report);
sessionRequest.setInputParameters(inputParameters);
IlrSessionResponse sessionResponse = session.execute(sessionRequest);
Report out_report = (Report)sessionResponse.getOutputParameters().get("report“);
And then you play with your "out" parameters... As you would do with any JAVA object
If you want to see them at debug time, I would say:
1/ (not tested) Have a look on the "working memory tab" in the debugger perspective
I am not sure but this is the easiest way to find them if it is visible here
2/ (tested) in the initial action of the starting point of your ruleflow, add:
context.insert(the technical name of your parameter);
Not the "business name". Anyway avoid using BAL in technical artifact such as ruleflow, IRL rules!
By doing this you force the engine to insert your parameter in the working memory.
No duplication (don't worry, it will work like a charm) but as far as I can remember this is the shortest way to make them visible in the Eclipse debugger in JRules
Hope it helps

Calling a Java Web Service from a .Net Project - Handling arrays

I am trying to call some web services written in Java from my asp.net code. I don't know Java.
There are several methods each with multiple properties. These methods are then passed to one controlling method. The problem occurs with how to handle arrays. I cannot seem to get the syntax quite right.
For example, there can be from 1 to n locations. Each location has multiple properties.
I can build one location ok. But how do I build an array of locations? I tried several approaches. Here is the closest I’ve gotten. It complies but crashes on the third to the last line below. I’ve removed the code that is not relevant to explaining the problem.
The error says: Object reference not set to an instance of an object.
WebReferenceMERegistration.getMERegistration _myMERegistration =
new WebReferenceMERegistration.getMERegistration();
WebReferenceMERegistration.Locations _myLocation =
new WebReferenceMERegistration.Locations();
WebReferenceMERegistration.Locations[] _myLocations = null;
_myLocation.AddressLine1 = txtEmployerAddress1.Text;
_myLocation.AddressLine2 = txtEmployerAddress2.Text;
// more properties set here
_myLocations[0] = _myLocation;
_myMERegistration.Locations = _myLocations;
_Results = _myRegistrationService.getMERegistration(_myMERegistration);
int length = ...;
WebReferenceMERegistration.Locations[] _myLocations =
new WebReferenceMERegistration.Locations[length];

Passing parameter to Java class using scripted DS in Birt

I have a method RunReport( rptfile, o/p path, emp_id);
which generate the report using scripted Data Source. I need to pass emp_id to the script
Open():
count = 0;
// Create instance of my class
p= new Packages.joez.sal();
//Load the List
s = p.getSal(emp_id);
where based on emp_id, the report is generated. Please let me know how to set the value of emp_id in Java class from script.
Thanks in advance :)
In the script you cite above, you simply need to properly reference the parameter so it can be passed in by value.
Change you call to getSal(...) to look like this:
s = p.getSal(params["emp_id"]);
That should be the only change you need.
Good Luck!

Categories

Resources