18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Is there any easier way to handle function invoking?
I am using the object orientate programming mode. My .sah file content is below. I assumed "_assertEqual("hello",this.method1())" should work but it does not. Now I have to define a variable first to get the method2() return value first to make it work but it looks redundant, doesn't it? Is there any easier to handle the function invoking from another function? Thanks.
======================
1 function ClassA(){
2 this.method1=function(){
3 return "hello"
4 }
5
6 this.method2=function(){
7 // this does not work now but it should work in normal JS code
8 //_assertEqual("hello",this.method1())
9
10 var $value=this.method1()
11 _assertEqual("hello",$value)
12 }
13 }
14
15 new ClassA().method2()
======================
1 function ClassA(){
2 this.method1=function(){
3 return "hello"
4 }
5
6 this.method2=function(){
7 // this does not work now but it should work in normal JS code
8 //_assertEqual("hello",this.method1())
9
10 var $value=this.method1()
11 _assertEqual("hello",$value)
12 }
13 }
14
15 new ClassA().method2()
Comments
OO javascript is pretty nice, I used http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript
But including Sahi APIs is tricky because some function calls in APIs need browser tags to work and I don't know if this is possible within a function.. see http://sahi.co.in/forums/viewtopic.php?pid=8237#p8237
Regards
Wormi
For your post. Actually it may not need "browser" tag. Instead, you can assign the function return value to a variable first if you don't like to put the function declaration into the browser tag. See below. Certainly if you function involves DOM operations, you have to put it into browser tag.
=======================================
function someFunction($string){
return $string;
}
var $result=someFunction("something")
_assertNotExists("something", "Here i want" + $result);
Is anybody using OO javascript these days with Sahi ?
If yes what are the main drawbacks