The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

Showing posts sorted by relevance for query sahi. Sort by date Show all posts
Showing posts sorted by relevance for query sahi. Sort by date Show all posts

20121112

[SOLVED] sahi - firefox closed unexpectedly while starting, running sahi with ant, NoClassDefFoundError

i'm trying to run a sahi test suite on my laptop and getting some weird behavior (open source [OS] version install_sahi_v35_20110719.jar).

here's my suite file, smoketest.suite:

// smoketest tests.  Run a few simple tests
test1.sah

test2.sah
test3.sah
test4.sah
test5.sah
test6.sah
test7.sah
test8.sah


i run this using ant (run target runSingleTestSahi):
    <target name="runSingleTestSahi">
        <antcall target="start-web" />
        <antcall target="sahiTest" />
        <antcall target="stop-web" />
    </target>


    <target name="sahiTest">
        <echo>testrunner start</echo>
        <exec executable="../testing/sahi/userdata/bin/testrunner.sh" failonerror="true" osfamily="unix">
            <arg value="smoketest.suite" />
            <arg value="http://a.localtestserver.no:8080" />
            <arg value="firefox" />
        </exec>
        <echo>testrunner end</echo>
    </target>

    <target name="start-web" description="starts web">
        <echo>start web start</echo>
        <exec executable="../testing/sahi/userdata/bin/start_sahi.sh" osfamily="unix" spawn="true"/>
        <echo>start web end</echo>
    </target>

    <target name="stop-web" description="stop web server">
        <echo>stop-web start</echo>
        <get dest="stopserver.htm" src="http://localhost:9999/dyn/stopserver" ignoreerrors="true" />
        <delete file="stopserver.htm"/>
        <echo>stop-web end</echo>
    </target>


when i run this smoketest.suite, firefox windows popup and i can see some of the scripts get run. after 150 seconds the script stops/times out and the log shows that some of the scripts are red. if i click on one it shows the following error:
ERROR
Script did not start within 150 seconds.


when i tried running the scripts that failed, individually, they would always give me the error:
firefox closed unexpectedly while starting...

but the second time i would run them, they would complete successfully.

SOLUTION:
i found out that it was the number of threads (default 5) defined in testrunner.sh that was causing the problem. when i changed it from 5 to 1 (cue doors music ;), then the whole suite ran without problems--it just takes more time to complete the test, but at least it works. :)

change:
export THREADS=5
to:
export THREADS=1


FULLY QUALIFIED PATHS IN SH SCRIPTS
another thing i had to do was convert all PATH values to fully qualified paths, instead of relative paths, otherwise, if i tried running the scripts with ant, it would give me the following error:
     [exec] Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/sahi/test/TestRunner
     [exec] Caused by: java.lang.ClassNotFoundException: net.sf.sahi.test.TestRunner
     [exec]     at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
     [exec]     at java.security.AccessController.doPrivileged(Native Method)
     [exec]     at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
     [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
     [exec]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
     [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
     [exec] Could not find the main class: net.sf.sahi.test.TestRunner. Program will exit.



files with PATHs that needed to be changed (change the red parts of the paths to where you installed sahi):
sahi/userdata/bin/start_sahi.sh
#################

#!/bin/bash
export SAHI_HOME=/home/me/eclipseWorkspace/myApp/testing/sahi
export SAHI_USERDATA_DIR=$SAHI_HOME/userdata
export SAHI_EXT_CLASS_PATH=
. $SAHI_HOME/bin/sahi.sh
 
#################


sahi/userdata/bin/testrunner.sh
#################
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: testrunner.sh <sah file|suite file> <startURL> <browserType>"
echo "File path is relative to userdata/scripts"
echo "Example:"
echo "testrunner.sh demo/demo.suite http://sahi.co.in/demo/ <browserType>"
echo "testrunner.sh demo/sahi_demo.sah http://sahi.co.in/demo/ <browserType>"
else

export SAHI_HOME=
/home/me/eclipseWorkspace/myApp/testing/sahi
export USERDATA_DIR=$SAHI_HOME/userdata
export SCRIPTS_PATH=
$USERDATA_DIR/scripts/$1
export BROWSER=$3
export START_URL=$2
export THREADS=1
export SINGLE_SESSION=true
java -cp $SAHI_HOME/lib/ant-sahi.jar net.sf.sahi.test.TestRunner -test $SCRIPTS_PATH -browserType "$BROWSER" -baseURL $START_URL -host localhost -port 9999 -threads $THREADS -useSingleSession $SINGLE_SESSION
fi

#################


sahi/bin/sahi.sh
#################
if [ ! $SAHI_HOME ]
then
    export SAHI_HOME=/
home/me/eclipseWorkspace/myApp/testing/sahi
fi
if [ ! $SAHI_USERDATA_DIR ]
then
    export SAHI_USERDATA_DIR_TMP=$SAHI_HOME/userdata
else   
    export SAHI_USERDATA_DIR_TMP=$SAHI_USERDATA_DIR
fi   

echo --------
echo SAHI_HOME: $SAHI_HOME
echo SAHI_USERDATA_DIR: $SAHI_USERDATA_DIR_TMP
echo SAHI_EXT_CLASS_PATH: $SAHI_EXT_CLASS_PATH
echo --------

SAHI_CLASS_PATH=$SAHI_HOME/lib/sahi.jar:$SAHI_HOME/extlib/rhino/js.jar:$SAHI_HOME/extlib/apc/commons-codec-1.3.jar
java -classpath $SAHI_EXT_CLASS_PATH:$SAHI_CLASS_PATH net.sf.sahi.Proxy "$SAHI_HOME" "$SAHI_USERDATA_DIR_TMP"

#################

see also how to run sahi tests as a sahi ant task

20121113

[SOLVED] sahi ant task - java.net.ConnectException: Connection refused

i created a sahi ant task to run a test suite:
<target name="runSahiTests">
    <antcall target="start-web" />
    <antcall target="runSahi" />
    <antcall target="stop-web" />
</target>

<target name="start-web" description="starts web">
    <exec executable="../testing/sahi/userdata/bin/start_sahi.sh" osfamily="unix" spawn="true"/>
</target>

<target name="stop-web" description="stop web server">
    <get dest="stopserver.htm" src="http://localhost:9999/dyn/stopserver" ignoreerrors="true" />
    <delete file="stopserver.htm"/>
</target>

<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="../testing/sahi/lib/ant-sahi.jar" />
<target name="failsahi" if="sahi.failed">
    <fail message="Sahi tests failed!" />
</target>
<target name="runSahi">
    <sahi suite="/home/me/workspace/myApp/testing/functional_testing/stage_1/sahi/smoketest.suite"
        browserType="firefox"
        baseurl="http://myserver.example.com:9001"
        sahihost="localhost"
        sahiport="9999"
        failureproperty="sahi.failed"
        haltonfailure="false"
        threads="1">
        <report type="html" />
        <report type="junit" logdir="/home/me/workspace/myApp/testing/sahi/userdata/temp/junit" />
    </sahi>
    <antcall target="failsahi" />
</target>


but when i ran it i would get the following error:
[sahi] java.net.ConnectException: Connection refused
[sahi]     at java.net.PlainSocketImpl.socketConnect(Native Method)


to fix this i inserted a sleep call in the start-web target:
<target name="start-web" description="starts web">
    <exec executable="../testing/sahi/userdata/bin/start_sahi.sh" osfamily="unix" spawn="true"/>

    <sleep seconds="5"/>
</target>


to give the sahi proxy server enough time to start up beforing running the sahi task.

i also noticed that red paths above had to be fully qualified paths instead of relative paths, otherwise the sahi task would start, but it would never do anything and i would have to kill it in order to stop it.

see also how to run sahi tests in ant build file using testrunner

20130314

sahi - how to test https gmail in firefox

i'm trying to use sahi to login to my gmail (using firefox) and click on a registration link in an email as a party of my company's sahi test case, but i'm getting the following errors:

ERROR
Step >_sahi._call(window.open("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2";), "gmailWindow");< did not complete in 150 seconds.

and

_popup("gmailWindow")._setValue(_textbox("Email"), "my_email_address@gmail.com");
Window/Domain not found: popupNameFromStep=gmailWindow; derivedName=; windowName=; windowTitle=; wasOpened=0; domain=



SOLUTION

1. click "firefox" in the sahi dashboard

2. click the link "SSL Manager"

3. copy each domain marked with a red dot, into a tab, prefixed by "https://", hit enter, accept security risk mumbo jumbo.

UPDATE 20130320: these are the domains that need to be accepted:
sahi.example.com
mail.google.com
ssl.google-analytics.com
accounts.google.com
sahi.example.com
accounts.youtube.com
gmail.com


4. go back to the default page: http://sahi.example.com/_s_/dyn/Driver_initialized (or close the ff window and reopen it) and open the sahi controller

5. choose my script, e.g. test_gmail_login.sah

my script code looks like this:
var $userMail = "my_email_address@gmail.com";
_setValue(_emailbox("Email"), $userMail);
_setValue(_password("Passwd"), _prompt("Enter gmail password:"));
_click(_submit("signIn"));

NOTE: the username field in gmail uses: _emailbox
NOT _textbox

6. set "https://gmail.com" as the "start url", click "set"

7. click "play"

so it DID seem to be an issue with SSL :)

---
NOTE:

this info is a repost from my original thread on the sahi forums, which i solved myself:
how to use sahi with gmail?


---
NOTE 2:

the sahi forum thread Problem with Automating gmail web page (HTTPS SSL certificate error)
suggests adding the following value:
xhr.wait_ready_states=2

at the end of the file:
sahi/userdata/config/userdata.properties

when using sahi in gmail. and the sahi documentation page troubleshooting sahi
suggests this value:
xhr.wait_ready_states=2,3

but in my case it seems to work without it.

---
NOTE 3:

sometimes when i first run the test, i get the following error message after logging into gmail:
Your browser's cookie functionality is turned off. Please turn it on.

all i have to do then is just click "set" in the sahi controller and run the test again and then it works.

20131211

[SOLVED] starting sahi dashboard gives "java.net.BindException: Address already in use"

i tried starting the sahi dashboard to run a script:
cd ~/workspaceEclipse/tcTrunk/testing/sahi/userdata/bin
./start_dashboard.sh ~/workspaceEclipse/tcTrunk/testing

but got the following error message:
java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
    at java.net.ServerSocket.bind(Unknown Source)
    at net.sf.sahi.Proxy.startProxy(Proxy.java:162)
    at net.sf.sahi.Proxy.access$000(Proxy.java:57)
    at net.sf.sahi.Proxy$1.run(Proxy.java:126)
    at java.lang.Thread.run(Unknown Source)


SOLUTION

i stopped my local jboss 7 server that was running in debug mode, and then i was able to open the sahi dashboard.

THE REASON

normally when you start sahi it tells you that it uses port 9999.

looking at the jboss console startup output, i could see that the reason sahi wasn't starting up was because port 9999 was already in use:

[org.jboss.as.remoting] (MSC service thread 1-7) JBAS017100: Listening on 127.0.0.1:9999
...
[com.myapp.utils.ContextFactorySingleton] (ServerService Thread Pool -- 70) ContextFactorySingleton initialized with the following values:
localserver = true
initialContextFactory = org.jnp.interfaces.NamingContextFactory
providerUrl = jnp://localhost:9999



UPDATE 20140310

so, in order to test on your local jboss 7 version in debug mode, using sahi, you need to change the conflicting port, 9999, here:

jboss-eap-6.1/standalone/configuration/takecargoconfiguration.xml (or standalone.xml, if you're using the default configuration file):

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:8888}"/>
    ...
</socket-binding-group>



Here, i've changed 9999 to 8888.


20130428

sahi - run block of code only if script called from another script

here's how you conditionally run a block of code in a sahi script (sahi_script2.sah), but only if that script first gets called by another sahi script (sahi_script1.sah).

#############sahi_script1.sah##############

//some sahi code ...

var $write_wd_to_file = true;

_include("sahi_script2.sah");    // RUN sahi_script2.sah

//some sahi code ...

########################################


#############sahi_script2.sah##############

//some sahi code ...

/*
IF YOU CALL sahi_script2.sah DIRECTLY, THEN THIS WONT GET RUN
*/
// $write_wd_to_file gets set in sahi_script1.sah
if($write_wd_to_file) {
    var $weeklyDepartureId = $routeplanName + "_WD";
    _writeToFile($weeklyDepartureId, "weekly_departure_id.txt", true);
    _wait(2000);
}

//some sahi code ...

########################################


sahi_script1.sah runs some code, then runs sahi_script2.sah, which writes a string to a file

if sahi_script2.sah gets runs directly, then that block of code won't get run and nothing will get written to a file.

20130301

[SOLVED] jsf/richfaces can't set id dynamically for use in sahi test: java.lang.IllegalArgumentException

i'm currently writing sahi scripts to test our web app. i ran into a problem with our dynamic trip table where there was no identifier for the delete image:




the delete button code looks like this:
<a4j:commandLink id="removeTRQlink" title="#{msg['label.trip.confirmRemoveTRQ']}" action="#{listRequestsDM.tripBean.setCurrentTripAndTRQ(listObj, trq)}" oncomplete="#{rich:component('removeTRQPanelTrip')}.show()" reRender="removeTRQPanelTrip">
  <h:graphicImage value="/images/icons/delete.gif" style="border:0" />
</a4j:commandLink>


when i tried setting the a4j:commandLink id dynamically (using the transport request receiver ref id, like this:
<a4j:commandLink id="#{trq.receiverRefId}" title="#{msg['label.trip.confirmRemoveTRQ']}" action="#{listRequestsDM.tripBean.setCurrentTripAndTRQ(listObj, trq)}" oncomplete="#{rich:component('removeTRQPanelTrip')}.show()" reRender="removeTRQPanelTrip">
  <h:graphicImage value="/images/icons/delete.gif" style="border:0" />
</a4j:commandLink>


i would get the following error:
java.lang.IllegalArgumentException

eventually, after reading the sahi documentation, i noticed that images can also be identified by title. and jsf/richfaces also allows setting the title value dynamically :)
<h:graphicImage value="/images/icons/delete.gif" title="#{trq.receiverRefId}" style="border:0" />

and here's the sahi script code:
_click(_image($tr_id));

then we don't need any proximity qualifiers and we can precisely match any transport request in the subtable! :)

NOTE: trq.receiverRefId == $tr_id

pages that helped me:
http://sahi.co.in/forums/discussion/3870/identifying-image-buttons-uniquely/p1
http://sahi.co.in/w/all-apis

20130307

sahi open source edition 3.5 - encrypted password workaround

this might not be what you were searching for, but apparently, only sahi pro offers encrypted passwords.

i am going to start on some admin scripts, testing our admin backend, but i don't want to put our admin user name and password in a sahi script file, so to get around this i'm going to make the scripts start after i've already manually logged in to the admin backend, i.e. no login function.

the limitation with this is that they can't be run in a suite. i have to start the sahi dashboard, choose my admin script, "Set", then log in with my admin credentials AND THEN "Run" the script.

UPDATE:
you can also semi-automate this by using sahi's "_prompt" functionality:
_setValue(_textbox("username"), _prompt("Enter your username:"));
_setValue(_password("password"), _prompt("Enter your password:"));

UPDATE 20130325:
you can also fully automate tests by reading admin login credentials (username, password) from a file, WITHOUT committing the contents of the file to version control.

here's how i implemented it:

//////////test_admin_login.sah/////////
_include("functions/common_functions.sah");
...
my_login_admin();
...
//////////////////////////////////////////////////

//////////common_functions.sah/////////
function my_login( $username, $password){
    _assert(_isVisible(_button("Login")));
    _setValue(_textbox("loginForm:username"), $username);
    _setValue(_password("loginForm:password"), $password);

    _click(_button("Login"));
    _assert(_isVisible(_label("Logged in as:")));
}
 

...
function my_login_admin(){
    var $ar = _readCSVFile("functions/admin_login_DO_NOT_COMMIT_THIS_FILE_WITH_ADMIN_USER_PASS_IN_IT.csv", "\t");
    my_login($ar[0][0], $ar[0][1]);
}

...
//////////////////////////////////////////////////

contents of the admin login credentials file committed to svn:
/////admin_login_DO_NOT_COMMIT_THIS_FILE_WITH_ADMIN_USER_PASS_IN_IT.csv///////

"" ""

//////////////////////////////////////////////////

contents of the admin login credentials file on your local machine:
/////admin_login_DO_NOT_COMMIT_THIS_FILE_WITH_ADMIN_USER_PASS_IN_IT.csv///////

"myAdminUser" "myAdminPassword"

 //////////////////////////////////////////////////

NOTE: those fields are tab-separated


20130312

[SOLVED] sahi - ERROR missing ( before function parameters

i was sahi testing the following function:

function do_must_change_password($invalid_security_policy_password, $valid_security_policy_password) {
    _setValue(_password("changePwForm:currentpassword"), $invalid_security_policy_password);
    _setValue(_password("changePwForm:newpassword"), $valid_security_policy_password);

    _setValue(_password("changePwForm:confirmnewpassword"), $valid_security_policy_password);
    _click(_button("changePwForm:changePwBtn"));
}


but sahi was throwing this error on the line highlighted in red:
ERROR
missing ( before function parameters.


i found out that you can't end a sahi function name with _password, so i had to change the function name to:
function do_must_change_pwd(...

and then it worked :)

i've noticed that this also applies to function names ending in:
_list
_file

UPDATE: it looks like this might be the list of function name restrictions:
sahi/config/normal_functions.txt

20130423

call another sahi script from already running sahi script

i have a sahi script that would like to call an already existing sahi script first so i don't duplicate code. the answer was pretty simple:
#######UseCaseTest_2.sah######

_include("../run_this_script_first.sah"); // UseCaseTest 1
...
// then run this code:
...
#############

thanks to this thread:
http://sahi.co.in/forums/discussion/1046/writing-test-scripts-calling-other-scripts-with-passing-arguments-/p1

20140321

[SOLVED] sahi, primefaces: p:dataTable no rendered table tag id

i'm updating our sahi test scripts for our new primefaces frontend and ran into a difficulty when trying to select a specific table row cell.

this page gives a hint as to how to select specific table cells:
http://sahi.co.in/docs/faq/get-cell-data.html

using this format:
_cell(_table("<table_identifier>"), x-1, y-1)


but the problem is that when a primefaces p:dataTable gets rendered to HTML, the table is enclosed in a div tag, and that div tag gets the id value set in the p:dataTable code, and the actual table tag doesn't have an id.

i solved my problem like this:
_cell(_table(1, _in(_div("selectMember:selectMemberTable"))), 1, 1)

here i specify the *second* table (there's a table in the header too), which is the actual dataTable table (0-based indexing, so value "1").

however, from what i can see, the sahi documentation is confusing concerning "x" and "y", if you interpret "x" to mean column (left<->right position), like i do.

"...1, 1)", in reality, means "row 2 (x), column 2 (y)" (0-based indexing, so "1, 1")

------------

as a side note, i found this sahi script code useful/interesting too:
_table(0, _in(_div("selectMember:selectMemberTable"))).rows[0].style='background-color:red'

which changes the background color of the first row of the first table to red.

20121119

phantomjs with sahi OS on ubuntu 8.10 -- /lib/libc.so.6: version `GLIBC_2.9' not found (required by ./phantomjs)

it looks like you can't run phantomjs with sahi on ubuntu 8.10 because the glibc/libc version is 2.8 and from this output, it looks like it needs 2.9+:
./phantomjs: /lib/libc.so.6: version `GLIBC_2.9' not found (required by ./phantomjs)
./phantomjs: /lib/libc.so.6: version `GLIBC_2.10' not found (required by ./phantomjs)
./phantomjs: /lib/libc.so.6: version `GLIBC_2.11' not found (required by ./phantomjs)
./phantomjs: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./phantomjs


i got this output by manually running phantomjs like this:
./phantomjs --proxy=localhost:9999 /home/me/myProject/testing/sahi/userdata/phantomjs-1.7.0-linux-x86_64/nick/sahi.js http://localhost:9999/_s_/dyn/Player_auto?startUrl=http%3A%2F%2Fmy.server.no%3A9001__SahiAmpersandSahi__sahisid=sahi_a4363cfb01c9904f8109e4702ddc52cbdb40sahix14e58ffa0de95046b12b2da051862a21417ex__SahiAmpersandSahi__isSingleSession=true

20130305

sahi - automated web form submit using values from tab separated csv file, in linux

here's a simple sahi script that reads a tab separated csv file into a 2 dimensional array, logs into mywebsite.com, navigates to a user profile page, and updates user input text field values for "first name" and "last name", saves (submits the user profile form), then logs out of mywebsite.com:

########test_read_file_and_update_user_name.sah###############

// start URL: http://mywebsite.com/login.jsf

var $ar = _readCSVFile("/home/me/userprofile.csv", "\t");

_setValue(_textbox("username"), "myusername");

_setValue(_password("password"), "mypassword");

_click(_button("log in"));

_click(_link("User profile"));

_setValue(_textbox("firstname"), $ar[0][0]);

_setValue(_textbox("lastname"), $ar[0][1]);

_click(_button("Save"));

_click(_link("log out"));


##########################################################

start URL is a comment showing what you manually paste into the sahi controller > playback > start url field

userprofile.csv looks like this in a text editor:
"nick"    "humphrey"

see part 1 of this tutorial:
sahi - automated web data extraction, export to tab separated csv file, in linux

20140403

[SOLVED] sahi (OS v4.4) "did not complete in 150"

i upgraded from sahi v3.5 to v4.4 and when i ran one of my scripts, sahi would hang after logging into the application i'm testing, and after waiting a while, it would finally return this error message:
"did not complete in 150"

i had stumbled across something similar to this before and had documented it here: sahi how to test gmail

that gave me some clues about what to do to fix it:
1. make sure all the https sites in SSL Manager were displayed with a green checkmark, instead of a red dot.

in my case, "localhost" had a red dot, but when i clicked on "localhost", there was no way to accept the self-signed SSL certificate permanently--i only saw this in the iframe:

localhost uses an invalid security certificate. The certificate is not trusted because it is self-signed. (Error code: sec_error_ca_cert_invalid)

so i had to open a new browser tab at this address:
https://localhost

then i could accept the certificate.

2. then, as an educated trial-and-error guess attempt, i found out i needed this line, in userdata.properties, to fix it entirely:

xhr.wait_ready_states=2

20130310

sahi - how to verify elements in new window (popup)

in our company's application we have a link that opens a new google maps window showing the GPS coordinates location of a transport request party.


i want to assert that the output is correct, so here's how i did it:

/////////////////////////////////
function view_tnt_trip_event_loc($tripId, $trip_event_loc) {
    view_tnt_by_tripId($tripId);
    _click(_link($trip_event_loc));
    $google_maps_window_prefix = $trip_event_loc+" - Google Maps";
    _popup($google_maps_window_prefix)._assert(_containsText(_textbox("gbqfq"), $trip_event_loc));
}

/////////////////////////////////

$trip_event_loc is a text string GPS coordinate, e.g.: "59.7692516149341,10.25079422084966"

$google_maps_window_prefix is simply the window title, e.g.:
"59.7692516149341,10.25079422084966 - Google Maps"

gbqfq is google's id for the maps window search textbox.

NOTE: when you run a sahi script that opens a new window, a new Sahi Controller window opens up for that new window. there you can find the _popup(identifier) (window title) in the "Prefix" field in the "Record" tab of that new Sahi Controller window.

thanks to this page for pointing me in the right direction:
How to switch between child and parent windows?

20130321

sahi - tip: you can use boolean operators in sahi functions

_assert(_isVisible(_button("Logg inn") || _button("Login")));

this checks that the login button on our login page is visible, whether it be in norwegian or english.

you can also use it for functions like _click():
_click(_button("Logg inn") || _button("Login"));

i wasn't previously aware that one could use boolean operators in sahi, since there seems to be no mention of it in the sahi apis.

20121218

sahi sah test script - ERROR missing ( before function parameters

i tried running a seemingly well-coded sahi test script, but i only got FAILURE every time i ran it. the log output was simply that my script was missing a left parenthesis somewhere (which wasn't the case i found out):
ERROR
missing ( before function parameters.


here's the sahi code that was failing:
...
view_invoice_specification_list();
...

and here's that function code:
function view_invoice_specification_list(){
    _click(_span("Fakturaspesifikasjon"));
    _assert(_isVisible(_tableHeader("Fakturaspesifikasjon")));
}



in the sahi dashboard i clicked "view parsed script" and saw the following weird output:
function view_invoice_specification_sahi._list(){
...
}

...
view_invoice_specification_sahi._list();
...


the problem turned out to be the use of the word "list" in the function name. i renamed the function name to view_invoice_specification_lst(), and then it worked. it also works if i put an underscore after "list", e.g. view_invoice_specification_list_()

20130214

sahi - how to click a span inside a table and match table id using regex

i have an html page rendered by richfaces which made things a little problematic for my sahi script test:

* even though the rich:dataTable had a hardcoded id:
<rich:dataTable id="providerListTA" ...

when the page gets rendered by richfaces, the id looks like this in the rendered html code:
id="j_id1045:providerListTA:tb"

* the table is rendered inside a rich:modalPanel and contains a list of providers to select. inside that table there's a row with a link in the first column that i want to click on
Provider X

the problem is that behind the modalpanel there's a list of price agreements which also contains "Provider X", so the following code doesn't work:
_click(_span($transporter_name));

specifying the element number also doesn't work because it will change from user to user, depending on what's in the price agreement list:
_click(_span($transporter_name[11]));

so i read the sahi api documentation and found out how to use the DOM relation marker called "_in", together with a regexp that matched only the hardcoded id in the xhtml/jsf code, leaving out the richfaces-appended texts, i.e. "j_id1045:" and ":tb":

_click(_span($transporter_name, _in(_table(/.*providerListTA.*/))));

Provider X is passed into the sahi script method as $transporter_name and the regex part of the code is this:
/.*providerListTA.*/

which means to match an id containing providerListTA with any characters in front or behind it.

20140311

[SOLVED] sahi include script does not exist

today's problem started out like this:

### verify_any_transport_requests.sah ###

_include("functions/common_functions.sah");
_include("functions/common_vars.sah");
_include("functions/transport_request_functions.sah");

tc_login($buyer_user_unil, $buyer_pass_unil);

listAllTRQsUnfiltered();

tc_logout();


###########################

every time i'd try running this script i'd get the following error in the sahi log:
ERROR
Script: /home/nick/workspaceEclipse/tcTrunk/testing/functional_testing/stage_1/sahi/functions/transport_request_functions.sah does not exist.



since i knew that the include file indeed did exist, i figured it had to be something wrong with the code. then i saw this code in transport_request_functions.sah:

_link("filtermenubarForm:filterBtn");

it should have been:
_click(_link("filtermenubarForm:filterBtn"));

it seems like that was the problem.

20130313

sahi/javascript - function to generate a random 13-digit gs1 gln number

i am currently making sahi tests for registering member applications for my employer and i needed a way to automatically generate a GLN number with a correct control/check digit, so here's my solution:

///////// SAHI CODE //////////

// function call
var $gln_base_id_number = Math.floor(Math.random()*900000000000) + 100000000000;    // 12-digit random number
var $gln_check_digit = generate_gln_check_digit($gln_base_id_number);

var $gln = $gln_base_id_number + "" + $gln_check_digit;    // convert the number to a string


// function
function generate_gln_check_digit($gln_base_id_number) {
    $gln_base_id_number = (""+$gln_base_id_number);    // convert the number to a string
    var $factor = 3;
    var $sum = 0;
    var $index = $gln_base_id_number.length;

    for ($index; $index > 0; --$index) {
        $sum = $sum + $gln_base_id_number.substring($index-1, $index) * $factor;
        $factor = 4 - $factor;
    }
    return ((1000 - $sum) % 10);
}


//////////////////////////////////////////////

///////// JAVASCRIPT CODE //////////

// function call
var gln_base_id_number = Math.floor(Math.random()*900000000000) + 100000000000;    // 12-digit random number
var gln_check_digit = generate_gln_check_digit(gln_base_id_number);

var gln = gln_base_id_number + "" + gln_check_digit;    // convert the number to a string


// function
function generate_gln_check_digit(gln_base_id_number) {
    gln_base_id_number = (""+gln_base_id_number);    // convert the number to a string
    var factor = 3;
    var sum = 0;
    var index = gln_base_id_number.length;

    for (index; index > 0; --index) {
        sum = sum + gln_base_id_number.substring(index-1, index) * factor;
        factor = 4 - factor;
    }
    return ((1000 - sum) % 10);
}


//////////////////////////////////////////////


i made this based on:
* gs1's online tool, which includes this external form
* gs1's javascript

20140321

sahi, primefaces: "ReferenceError: PrimeFaces is not defined". solution: just rerun the sahi script

sometimes when i run a sahi script to test our primefaces ui, the script times out with the following error:

ReferenceError: PrimeFaces is not defined (http://localhost/pages/listTransportAgreements.jsf:278)

when i rerun the script, it usually goes away, so i'm not quite sure why it works sometimes and other times it doesn't.