Skip to main content

How to export multiple values from Interview

3 replies [Last post]
murali_reddy219
Offline
Joined: 2007-10-25

Hi Vladimir,

Things are going well. Now i am able to create my own interview and execute tests.

But i have one doubt. Suppose i want to use array of URLs(i.e for example 5 URLs).How can i give 5 urls for one interview question and How can we get them in decodeArgs method in tests class.

Ex: I need 5 valid url paths to check whether they are valid or not.Then can i give as array of strings. If it is ,then how can we do.

plz give me sample example with code

Thanks,
Murali

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vsizikov
Offline
Joined: 2004-11-16

Hi Murali,

As you've probably noticed I moved your question into a separate thread, for convenience.

> Things are going well. Now i am able to create my own
> interview and execute tests.

That's good to hear! :)

> But i have one doubt. Suppose i want to use array of
> URLs(i.e for example 5 URLs).How can i give 5 urls
> for one interview question and How can we get them
> in decodeArgs method in tests class.

That could be pretty straightforward. First, you need to use
appropriate Question type, and most suitable for your case is probably StringListQuestion (from com.sun.interview package), this is
a JTHarness class.

The question will allow you (and your users) to enter a list of strings
in a single question. In this question you'll ask users to enter the URLs.

Question's getValue() method will return an array of strings that users entered.

Then, you just export them to the Test Environment somehow. And there are multiple approaches to do that.

Most typical approach:Just concatenate the string values, separated by space into a single string (and Question's getStringValue() might do just that), and then you'll export the resulting string into the TestEnvironment, e.g.:

data.put("testURLS", your_concatenated_string);

And in the test code, in the args, you'll have something like:
... -testURLS $testURLS ....

The Harness will resolve the $testURLS and inserts your value instead of the variable,
and passes to the test.

In the test you'll parse the command line and obtain the results.

> Ex: I need 5 valid url paths to check whether they
> are valid or not.

Yep, the receipt above is suitable for this. Most probably, you should
check the URL validity right in the interview question, so that users
immediately notified about problems if the enter something wrong.

Thanks,
--Vladimir

murali_reddy219
Offline
Joined: 2007-10-25

Hi Vladimir,

I am not getting. Plz tell me with some example how to do the steps.

I had given like this.

private StringListQuestion listURLs = new StringListQuestion(this,"ListURLs") {
protected Question getNext() {
return listURLs;
}
public void export(Map data) {
System.out.println("[ DRMTCKInterview ] [export ] NonexistURL Value is = " + value);
data.put("listURLs", value);
}
};
If this is correct, then how we will decode args in test case class in decodeArg() method,
plz give example code .

Thanks
Murali

vsizikov
Offline
Joined: 2004-11-16

Hi Murali,

> private StringListQuestion listURLs = new
> StringListQuestion(this,"ListURLs") {
> protected Question getNext() {
> return listURLs;
> }

Here, in getNext() you should specify the name of the next question, not
the same question, or the interview will loop, and will not end.

> this is correct, then how we will decode args in
> test case class in decodeArg() method,
> lz give example code .

I've prepared an example code, here's the link:
https://cqme.dev.java.net/source/browse/cqme?rev=1460&view=rev

Click on "text changed" links for every file name to see the changes.
In SampleInterview, I export the list of URLs, in index.html I add
neccessary things (environment variable $testUrlArgs) to executeArgs, and finally
in Test2.java I add the parsing of the parameters, exported from the interview.

Let me know if that resolves your question.