cancel
Showing results for 
Search instead for 
Did you mean: 

"/" from string read from file becomes "\\" in testcomplete.

New Contributor

"/" from string read from file becomes "\\" in testcomplete.

I am trying to reading a value Username = WIN7\admin from a file in system. but in test complete it becomes "\\" and Username becomes WIN7\\admin. So going further I get error username is invalid. Please advise how to modify the code such that I can keep username value with one"\".

4 REPLIES 4
New Contributor

Re: "/" from string read from file becomes "\\" in testcomplete.

Sorry title is wrong. - "\" from string read from file becomes "\\" in testcomplete.

Community Hero

Re: "/" from string read from file becomes "\\" in testcomplete.

What language are you writing your code in?

The reason I ask is that it's probably an artifact of the language.  JavaScript requires that the \ character in a string, in order for it to be properly used, needs to be \\.  

It would be helpful, also, if you share your code... asking to help fix your code without actually seeing your code is a bit tricky...


Robert Martin
[Community Expert Group]
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
Extensions available
New Contributor

Re: "/" from string read from file becomes "\\" in testcomplete.

I am using Javascript. here is example code snippet,

 

var url = "10.10.199.22";
var username = "WIN7-Test01\admin";
var password = "password";

Sys.OleObject("WScript.Shell").Run("cmdkey /add:" + url + " /User:" + username + " /pass:" + password );

 

WIN7-Test01\admin becomes WIN7-Test01admin

WIN7-Test01\\admin becomes WIN7-Test01\\admin

WIN7-Test01\\\admin becomes WIN7-Test01\\admin

 

Thanks.

 

Community Hero

Re: "/" from string read from file becomes "\\" in testcomplete.

Because it's JavaScript, you need to make sure that the \ is "escaped" properly.  The proper way to process this is as so:

 

var url = "10.10.199.22";
var username = "WIN7-Test01\\admin";
var password = "password";

Sys.OleObject("WScript.Shell").Run("cmdkey /add:" + url + " /User:" + username + " /pass:" + password );

This will work.  While you are correct, the string reflects the \\, when it's actually interpreted into the Run command, it will have the proper number of characters.


Robert Martin
[Community Expert Group]
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
Extensions available
New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors