Question

Is it possible to dynamically get record fields in Silk4Test?

Let's say we have this record:

[-] type testRec is record
    [ ] string a
    [ ] int b
    [ ] string c
    [ ] string d

And this list:

list of string lsFields = {"a", "d"}

Is there a way to set only fields that are in lsFields to a specific value? Let's say I need to set them to "TEST", how would I do that? Is it even possible?

Était-ce utile?

La solution

Yes, it should be possible using the @-operator which allows executing string contents as 4Test code.

Something like the following (I'm just typing it from the top of my head, not sure if it is syntactically correct, don't have access to Silk Test at the moment).

[ ] string fieldName
[-] for each fieldName in lsFields
    [ ] rec.@fieldName = someValue

What this code does is that it interprets the contents of fieldName as member of recand assigns someValue.

Depending on the context you might want to wrap it in a do-except-block, because it will throw an exception if the member does not exist. Alternatively, you could also check with the IsDefined-function if the record contains the desired field.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top