cancel
Showing results for 
Search instead for 
Did you mean: 

Verifiy link address on firefox

SOLVED
Highlighted
Occasional Contributor

Verifiy link address on firefox

Hi, I am still exploring on how TestComplete works.

 

Currently, I am trying to create a test to verifiy the support link provided on the software opens the expected website address.

 

As I have limited knowledge on the scripting, I am using keyword test method. When I recorded the test and used property checkpoint on the address bar, for example, i want to verify that the website address is 'https://community.smartbear.com/', it didn't show any Text property, only caption, and it didn't work.

 

When I tried to run it, it shows warning message, 'The "Text" property of the "Stub object" object does not meet the checkpoint's condition',

I am not sure why the address bar on the firefox is considered as a Stub object. 

Could anyone please help me how to verify website link inside the address search bar (I think it's a combobox)?

 

Thank you.

 

Kind regards,

Ran

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Verifiy link address on firefox

lol ... no it was an example MyValue Smiley Happy

 

So here you must make that,

function CheckWebURL(UrlToCheck) { 
//Assuming that no need of browser exists check so just check if an url is given to be checked and if current browser current page url contains this url
if (typeof UrlToCheck == 'string') {
var posUrl = aqString.Find(Sys.Browser("*").Page("*").URL, UrlToCheck, 0 , false);
return ((UrlToCheck != "") && (posUrl >=0) && (posUrl < 9))
}
else {
Log.Message("UrlToCheck is incorrect");
return false;
}
}

typeof return the type of the variable

it could be 'undefined', 'string', 'number' or 'Object'  (array are included in Object)

Here you want a string, so checking if type is string is double check:  variable is definied and it's type is string.

 

On your function, MyValue is here not defined ...

And it will return return true, because by default function returns true. And you don't specify the return value in case of bad type (Log.Message doesn't change return value, Log.Error yes).

 

Good place to learn data type here:

https://www.w3schools.com/js/js_datatypes.asp

 

 

Un sourire et ça repart

View solution in original post

12 REPLIES 12
Highlighted
Community Leader

Re: Verifiy link address on firefox

To check the current bar url in current active browser is as simple as checking the Sys.Browser("*").Page("*").URL value

 

Un sourire et ça repart

Highlighted
Community Leader

Re: Verifiy link address on firefox

@rancan  did you need more info on check address bar ?

If yes, please continue to discuss here and if it's ok you can click Accept solution..

Un sourire et ça repart

Highlighted
Occasional Contributor

Re: Verifiy link address on firefox

Hi,

 

Sorry for the late response and thank you for replying on my question. 

 

I tried to write a script as you said, however, i got the warning Ms Jscript Runtime error. 

As I am not familiar with coding, here's what I have:

 

function CheckWeb()
{

// Obtains the browser process
var browser = Sys.Browser("firefox");
// Obtains the page currently opened in Mozilla firefox
var page = browser.Page("*");

try{
if (page == "www.google.com")
{
Log.Message("Support link checkpoint success " + page);
}
}

catch(e)
{
//Handle exception
Log.Message("Error: "+ e.name, e.description);
}
}

 

Could you please help me with this? 

Thank you very much

Highlighted
Community Leader

Re: Verifiy link address on firefox

you get the page object but you have to check the URL property so the test is
if (page.URL == "your adress")

But beware that page url can contains also all variables stuff starting at the end of the url with the ? sign
So instead equality its better to use aqString.Find() or aqString.Contains()

 

function CheckWebURL(UrlToCheck = "") {
  // Assuming that no need of browser exists check so just check if an url is given to be checked and if current browser current page url contains this url
  return ((UrlToCheck != "") && (aqString.Find(Sys.Browser("*").Page("*").URL, UrlToCheck, 0 , false) != -1))
}

But this method is incomplete  because if you have an url like http://myapp.jsp?errorvalue=www.google.com it will return true ..

 

So ..

 

function CheckWebURL(UrlToCheck = "") {
  // Assuming that no need of browser exists check so just check if an url is given to be checked and if current browser current page url contains this url
  let posUrl = aqString.Find(Sys.Browser("*").Page("*").URL, UrlToCheck, 0 , false);
  return ((UrlToCheck != "") && (posUrl >=0) && (posUrl < 9))
}

aqString.Find will return position into given string of the substring, -1 if not found so greater than -1

But why < 9 ?

Because if you give short url without protocol, you may prevent of that.

Commons protocol are ftp://, http:// https://, mailto:   so longest is https:// which is 8 characters long.

 

You can improve and secure this method with managing the current browser in use at global level (instead of using Browser("*"), use Browser(currentBrowser)), it's useful in tests with multiples browsers used in same time. Or pass the browser name in parameter of the function.

 

 

 

 

 

Un sourire et ça repart

Highlighted
Occasional Contributor

Re: Verifiy link address on firefox

Hi,

 

Thank you very much on the explanation, beforehand, this might be a stupid question,

in JavaScript, would it be possible to write "" in this 

function CheckWebURL(UrlToCheck = ""){
...
}

 Because it's giving me error.

 

Thank you very much. 

Highlighted
Community Leader

Re: Verifiy link address on firefox

I use javascript and the sample i given to you works in my TC 14.3

You can write " " or ' '  

Normally one is for string, the other is for single character but this is in theory, you can use both as string delimiter.

  • If you want write Hello grand'ma -> "Hello grand'ma" it's ok
  • If you want write He said "come with us" -> 'He said "come with us"'
  • If you want mix, use escape character which is \,  He said "Hello grand'ma" ->   "He said \"hello grand'ma"  or  'He said "Hello grand\'ma"'

Un sourire et ça repart

Highlighted
Occasional Contributor

Re: Verifiy link address on firefox

I am currenty using TestComplete 12, would it make any difference? 

 

 

Highlighted
Community Leader

Re: Verifiy link address on firefox

Yes, in TC 12 you can't use default value in function header. So;
function CheckWebUrl(UrlToCheck) {
}
To control if a value is defined check with;
if (typeof MyValue != 'undefined')

Un sourire et ça repart

Highlighted
Occasional Contributor

Re: Verifiy link address on firefox

Thank you very very much for helping me out. 

So here's what I have..

 

function CheckWebURL(UrlToCheck) {
  //Assuming that no need of browser exists check so just check if an url is given to be checked and if current browser current page url contains this url
 if (typeof MyValue != 'undefined'){
  var posUrl = aqString.Find(Sys.Browser("*").Page("*").URL, UrlToCheck, 0 , false);
  return ((UrlToCheck != "") && (posUrl >=0) && (posUrl < 9))
 }
 else{
  Log.Message("Error on identifying the link");
 }
}

However, it gave me the result of the else condition, instead, "error on identifying the link", did I put the if on the wrong spot?

Oh wait.. I didn't define what MyValue is...

 

Or perhaps, is it because I am using Firefox? Because when I tried to use Keyword test, the search bar doesn't have text/caption property, and it stated 'stub object doesn't have text property'

 

Thank you.

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!