How to convert a string to a Object
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to convert a string to a Object
Muhammad Mazhar Mahmood
Certified Software Tester (CSTE)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should use either Eval() (for VBScript and, possibly, for JScript/C#Script/C++Script) or evaluate() (for DelphiScript) function provided by the corresponding scripting language that you are using for the tests. See the documentation for the scripting language for more details. (Note: C#Script and C++Script are actually JScript with modified syntax, so you should read JScript documentation is you use any of these languages.)
For the VBScript the code will be like this:
strObject = "Sys.Process(""Notepad"")"
Set obj = Eval(strObject)
For DelphiScript the code will be like this:
strObject := 'Sys.Process(''Notepad'')'
obj := evaluate(strObject)
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Muhammad Mazhar Mahmood
Certified Software Tester (CSTE)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to set_color of a object. I have to convert the hex color pattern (Ex: "000080") to object to pass it as a parammeter to PathOfObject.set_SelectedColor(). Please help me to do this conversion in Vb Scripting.
Note: PathOfObject.set_SelectedColor "#000080"
It shows the following error if I run the above line of code.
Object of type "System.String" cannot be converted to type of "System.Windows.media.Color type"
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How should we achieve the same using python in Testcomplete. I understand evaluate() and Eval() can be used for jscript and delphy.
Can somebody please help on this. its an urgent requirement.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quick google search found that Python supports an "eval()" method as well. have you tried that?
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes . but it didnt work.
Query in detail: I trying to automate notepad.
enter some value in notepad.
the workspace path is = Aliases.notepad2.wndNotepad
if am trying to enter the value as = Aliases.notepad2.wndNotepad.Keys("Hello world"), then it is entering the word . but when i put the path in excel and trying get the path from excel and trying to enter value like = DDT.CurrentDriver.Value["columnName"].Keys("Hello world") >> then its throwing error as string doesnt have keys attribute.
please help in resolving this.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As mentioned, you need to use eval. I don't know Python so the syntax may be off. But, this is what I would do
var myObject; myObject = eval(DDT.CurrentDriver.Value["columnName"]); myObject.Keys('Hello World');
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Sir. Appreciate your help, That worked.
