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
IT, computer and programming tutorials and tips that i couldnt find anywhere else using google, from my daily work as a Senior Developer of solutions using Java and Linux.
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 date for query sahi. Sort by relevance Show all posts
Showing posts sorted by date for query sahi. Sort by relevance Show all posts
20140403
20140402
[SOLVED] sahi _setSelected not working with primefaces 4, but works with richfaces 3. workaround
back when we were using richfaces 3, this code worked fine:
_setSelected(_select("myForm:ChrgTrsTbl:0:price_chargeCode_input"), "CustClearance");
but it doesn't seem to work with primefaces 4. this, however, seems to work fine:
_click(_listItem("CustClearance"));
_setSelected(_select("myForm:ChrgTrsTbl:0:price_chargeCode_input"), "CustClearance");
but it doesn't seem to work with primefaces 4. this, however, seems to work fine:
_click(_listItem("CustClearance"));
20140331
sahi, suggestion: "_wait(maxTime, condition)" with "AND" functionality, not just "OR" -- stop execution if "condition" returns false
i wish there was an additional "_wait(maxTime, condition)" function that would stop execution if condition returns false.
as of now, it seems as if "wait + condition" continues execution no matter the outcome of "condition", which makes it an "OR" test, but my suggestion would be for an "AND" test, i.e.:
wait, up until maxTime is reached, and if condition is still false, then stop execution.
i want this because of network/server response timing issues, specifically related to ajax operations.
UPDATE
i just posted this as a discussion in the sahi forums:
suggestion for _wait: stop execution if condition returns false
UPDATE, WORKAROUND
to achieve the same thing today, it looks like you'd have to code it like this:
_wait(10000, _assertTrue(_isVisible(_link("detailsForm:saveAgreementBtn"))));
_assertTrue(_isVisible(_link("detailsForm:saveAgreementBtn")));
and this gives the same functionality, but with less code, but also may look potentially confusing:
_wait(10000, _isVisible(_link("detailsForm:saveAgreementBtn")));
_assertTrue(_isVisible(_link("detailsForm:saveAgreementBtn")));
as of now, it seems as if "wait + condition" continues execution no matter the outcome of "condition", which makes it an "OR" test, but my suggestion would be for an "AND" test, i.e.:
wait, up until maxTime is reached, and if condition is still false, then stop execution.
i want this because of network/server response timing issues, specifically related to ajax operations.
UPDATE
i just posted this as a discussion in the sahi forums:
suggestion for _wait: stop execution if condition returns false
UPDATE, WORKAROUND
to achieve the same thing today, it looks like you'd have to code it like this:
_wait(10000, _assertTrue(_isVisible(_link("detailsForm:saveAgreementBtn"))));
_assertTrue(_isVisible(_link("detailsForm:saveAgreementBtn")));
and this gives the same functionality, but with less code, but also may look potentially confusing:
_wait(10000, _isVisible(_link("detailsForm:saveAgreementBtn")));
_assertTrue(_isVisible(_link("detailsForm:saveAgreementBtn")));
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.
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.
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.
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.
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.
### 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.
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.
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.
20131010
sahi - how to assert whether an html select option is selected or not
_option("FullReceived").selected
the above code is just a partial. here are some examples of implementations:
assuming that it IS selected, i.e. expecting a "true" value to be returned:
_assert(_option("FullReceived").selected);
and if/else test:
if(_option("FullReceived").selected) {
...
} else {
...
}
the above code is just a partial. here are some examples of implementations:
assuming that it IS selected, i.e. expecting a "true" value to be returned:
_assert(_option("FullReceived").selected);
and if/else test:
if(_option("FullReceived").selected) {
...
} else {
...
}
20130913
sahi - how to access a specific table cell using regex when the cell doesn't have an id
here's some relevant, rendered HTML from a richfaces rich:dataTable for the image above:
...
<tbody id="invFormremoveTRQPanel:removeTrqPnlTbl:tb">
<tr class="rich-table-row rich-table-firstrow row1">
<td id="invFormremoveTRQPanel:removeTrqPnlTbl:0:j_id159" class="rich-table-cell wsS ">
<input type="checkbox" name="invFormremoveTRQPanel:removeTrqPnlTbl:0:j_id161"></input>
</td>
<td id="invFormremoveTRQPanel:removeTrqPnlTbl:0:j_id162" class="rich-table-cell wsS ">
X_TRQ_13144907
</td>
...
the green code represents the first row's second column. the red code is a random id string generated by richfaces because in the xhtml/jsf file, there was no id set for the cell:
...
<rich:column>
<f:facet name="header">#{msg['label.rcvrRefId']}</f:facet>
<h:outputText value="#{trq.getRcvrRefId()}" />
</rich:column>
...
here's one way to access the element using regexp:
_cell(/invFormremoveTRQPanel:removeTrqPnlTbl:0:*/+"[1]")
invFormremoveTRQPanel:removeTrqPnlTbl:0 == the row identifier
/.../ == regular expression code
* == match any auto-generated id string, e.g. j_id162, this will match every column in the first row
so to specify which column (0-based) we want we write [1]
sahi - how to get tomorrow's date in the format dd.MM.yyyy
i needed a simple way to generate a date string so i could set a rich:calendar textbox input field using a sahi script, so here's sample code for one solution to generating tomorrow's date as a text string:
var $formattedDate = java.util.Calendar.getInstance();
$formattedDate.add(java.util.Calendar.DAY_OF_YEAR, 1);
$formattedDate = new java.text.SimpleDateFormat("dd.MM.yyyy").format($formattedDate.getTime());
_alert($formattedDate);
which will give output like:
14.09.2013
it's cool how you can call java directly in the sahi code :)
thanks to the post how to add the specific number of days to a date which was obtained
var $formattedDate = java.util.Calendar.getInstance();
$formattedDate.add(java.util.Calendar.DAY_OF_YEAR, 1);
$formattedDate = new java.text.SimpleDateFormat("dd.MM.yyyy").format($formattedDate.getTime());
_alert($formattedDate);
which will give output like:
14.09.2013
it's cool how you can call java directly in the sahi code :)
thanks to the post how to add the specific number of days to a date which was obtained
20130910
sahi - regex how to specify an indeterminate row number for a textfield element in a table row column
i have a datatable that expands with a new row every time i click an "add new row" button, and only the new row will have an editable textfield input, so to generalize the sahi script code you can use a regex, so it will match whichever single row has a visible textfield input:
_setValue(_textbox(/detailForm:agrSCFactorsTable:\d{1}:SCF_nameIn/), $name);
\d{1} means a digit (number) with 1 in length, i.e. 0-9.
so that regex will match elements like:
_setValue(_textbox(/detailForm:agrSCFactorsTable:0:SCF_nameIn/), $name);
...
_setValue(_textbox(/detailForm:agrSCFactorsTable:3:SCF_nameIn/), $name);
...
_setValue(_textbox(/detailForm:agrSCFactorsTable:7:SCF_nameIn/), $name);
...
_setValue(_textbox(/detailForm:agrSCFactorsTable:\d{1}:SCF_nameIn/), $name);
\d{1} means a digit (number) with 1 in length, i.e. 0-9.
so that regex will match elements like:
_setValue(_textbox(/detailForm:agrSCFactorsTable:0:SCF_nameIn/), $name);
...
_setValue(_textbox(/detailForm:agrSCFactorsTable:3:SCF_nameIn/), $name);
...
_setValue(_textbox(/detailForm:agrSCFactorsTable:7:SCF_nameIn/), $name);
...
20130904
[SOLVED] sahi "for loop" not working
i noticed on the sahi "for loops" documentation page that the for loop variable "i" wasn't being declared with a dollar sign ( $ ):
for (var i=0; i<links.length; i++){
...
so when i wrote a for loop in one of my tests i decided to insert a dollar sign for consistency purposes (so all variables used the dollar sign):
function setTimeFutureHours($hrs) {
...
for(var $i=0; i<$hrs; $i++) {
...
}
}
but when i ran the code, the for loop never ran. i quickly realized that i hadn't put a dollar sign next to the "i" in the middle, so i changed it and it ran perfectly:
function setTimeFutureHours($hrs) {
...
for(var $i=0; $i<$hrs; $i++) {
...
}
}
just out of curiosity, i tried the code without dollar signs next to the "i", like the documentation said and that also worked; you just have to be consistent and either use dollar signs on all of the variables in the for loop phrase or don't use dollar signs ;)
for (var i=0; i<links.length; i++){
...
so when i wrote a for loop in one of my tests i decided to insert a dollar sign for consistency purposes (so all variables used the dollar sign):
function setTimeFutureHours($hrs) {
...
for(var $i=0; i<$hrs; $i++) {
...
}
}
but when i ran the code, the for loop never ran. i quickly realized that i hadn't put a dollar sign next to the "i" in the middle, so i changed it and it ran perfectly:
function setTimeFutureHours($hrs) {
...
for(var $i=0; $i<$hrs; $i++) {
...
}
}
just out of curiosity, i tried the code without dollar signs next to the "i", like the documentation said and that also worked; you just have to be consistent and either use dollar signs on all of the variables in the for loop phrase or don't use dollar signs ;)
sahi - how to set a richfaces rich:inputNumberSpinner value and verify it got set correctly
i have the following form composed of a rich:calendar and 2 rich:inputNumberSpinner elements:
<a4j:form id="dateAndTimeSetterForm">
<h:panelGrid id="dateAndTimeSetter" style="border:1px" columns="1">
<h:panelGrid style="border:0px;width:100%;align:center" columns="1">
<rich:calendar
requiredMessage="#{msg['label.timeRequired']}"
value="#{listTRQsDataModel.requestHandler.dateInEditPosition}"
required="#{listTRQsDataModel.requestHandler.dateTimeMandatory}"
locale="#{userMenuBean.userLocale}" direction="auto"
id="dateSetterCal" popup="false" showInput="true"
showApplyButton="false" datePattern="#{msg['calendar.datePattern']}" cellWidth="24px"
cellHeight="22px" style="width:200px;align:center;">
<a4j:support event="onchanged" ajaxSingle="true"
reRender="hourSpinner, minuteSpinner" />
</rich:calendar> </h:panelGrid>
<h:panelGrid style="border:0px;width:100%;align:center;"
columns="2">
<h:outputLabel style="align:right"
value="#{msg['label.hour']}" />
<h:outputLabel
value="#{msg['label.minute']}" />
<rich:inputNumberSpinner id="hourSpinner" minValue="0"
style="align:right" maxValue="23" inputSize="2"
value="#{listTRQsDataModel.requestHandler.hourForTimeInEditPosition}" />
<rich:inputNumberSpinner id="minuteSpinner" minValue="0"
maxValue="59" inputSize="2"
value="#{listTRQsDataModel.requestHandler.minuteForTimeInEditPosition}" />
</h:panelGrid>
<h:panelGrid style="border:0px;align:center;" columns="1">
<a4j:commandButton id="setTimeBtn" style="align:center"
styleClass="regularbutton"
action="#{listTRQsDataModel.requestHandler.saveDateInPosition}"
oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('time_panel_trq')}.hide()"
reRender="#{listTRQsDataModel.requestHandler.dateIdentInEditPosition}"
value="#{msg['label.setTime']}" />
</h:panelGrid>
</h:panelGrid>
</a4j:form>
which looks like this in a browser:
the following sahi code ...
* opens this date+time setting modal panel
* gets the current hour value (originally "12")
* clicks the "up arrow" icon for hour ("Time" in norwegian) to make the hour "13"
* verifies that the hour got set correctly
* then clicks the "set time" submit button ("Sett tid" in norwegian)
* then verifies that the modal panel is closed--the submit button is no longer visible
function set_trq_pickup_time_future_1_hr() {
_click(_link("trq_det_form:setTimefirstpickupdate"));
_wait(10000, _isVisible(_button("dateAndTimeSetterForm:setTimeBtn")));
var $currentHour = _fetch(_textbox("dateAndTimeSetterForm:hourSpinner").value);
// clicks the first hour spinner based on class--there are two and "up 1 hour" is on top, i.e. first, so "down 1 hour" would be "rich-spinner-btn rich-spinner-button[1]"
_click(_imageSubmitButton("rich-spinner-btn rich-spinner-button", _in(_table("dateAndTimeSetterForm:hourSpinnerButtons"))));
var $newHour = ($currentHour+1);
_wait(_textbox("dateAndTimeSetterForm:hourSpinner").value == $newHour);
_click(_button("dateAndTimeSetterForm:setTimeBtn"));
_wait(10000, _isVisible(_button("dateAndTimeSetterForm:setTimeBtn")) == false);
}
<a4j:form id="dateAndTimeSetterForm">
<h:panelGrid id="dateAndTimeSetter" style="border:1px" columns="1">
<h:panelGrid style="border:0px;width:100%;align:center" columns="1">
<rich:calendar
requiredMessage="#{msg['label.timeRequired']}"
value="#{listTRQsDataModel.requestHandler.dateInEditPosition}"
required="#{listTRQsDataModel.requestHandler.dateTimeMandatory}"
locale="#{userMenuBean.userLocale}" direction="auto"
id="dateSetterCal" popup="false" showInput="true"
showApplyButton="false" datePattern="#{msg['calendar.datePattern']}" cellWidth="24px"
cellHeight="22px" style="width:200px;align:center;">
<a4j:support event="onchanged" ajaxSingle="true"
reRender="hourSpinner, minuteSpinner" />
</rich:calendar> </h:panelGrid>
<h:panelGrid style="border:0px;width:100%;align:center;"
columns="2">
<h:outputLabel style="align:right"
value="#{msg['label.hour']}" />
<h:outputLabel
value="#{msg['label.minute']}" />
<rich:inputNumberSpinner id="hourSpinner" minValue="0"
style="align:right" maxValue="23" inputSize="2"
value="#{listTRQsDataModel.requestHandler.hourForTimeInEditPosition}" />
<rich:inputNumberSpinner id="minuteSpinner" minValue="0"
maxValue="59" inputSize="2"
value="#{listTRQsDataModel.requestHandler.minuteForTimeInEditPosition}" />
</h:panelGrid>
<h:panelGrid style="border:0px;align:center;" columns="1">
<a4j:commandButton id="setTimeBtn" style="align:center"
styleClass="regularbutton"
action="#{listTRQsDataModel.requestHandler.saveDateInPosition}"
oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('time_panel_trq')}.hide()"
reRender="#{listTRQsDataModel.requestHandler.dateIdentInEditPosition}"
value="#{msg['label.setTime']}" />
</h:panelGrid>
</h:panelGrid>
</a4j:form>
which looks like this in a browser:
the following sahi code ...
* opens this date+time setting modal panel
* gets the current hour value (originally "12")
* clicks the "up arrow" icon for hour ("Time" in norwegian) to make the hour "13"
* verifies that the hour got set correctly
* then clicks the "set time" submit button ("Sett tid" in norwegian)
* then verifies that the modal panel is closed--the submit button is no longer visible
function set_trq_pickup_time_future_1_hr() {
_click(_link("trq_det_form:setTimefirstpickupdate"));
_wait(10000, _isVisible(_button("dateAndTimeSetterForm:setTimeBtn")));
var $currentHour = _fetch(_textbox("dateAndTimeSetterForm:hourSpinner").value);
// clicks the first hour spinner based on class--there are two and "up 1 hour" is on top, i.e. first, so "down 1 hour" would be "rich-spinner-btn rich-spinner-button[1]"
_click(_imageSubmitButton("rich-spinner-btn rich-spinner-button", _in(_table("dateAndTimeSetterForm:hourSpinnerButtons"))));
var $newHour = ($currentHour+1);
_wait(_textbox("dateAndTimeSetterForm:hourSpinner").value == $newHour);
_click(_button("dateAndTimeSetterForm:setTimeBtn"));
_wait(10000, _isVisible(_button("dateAndTimeSetterForm:setTimeBtn")) == false);
}
20130830
sahi - how to get/fetch html table cell (td) content value
to get a table cell contents/value use .innerHTML
the variable $rpNameRow1, after the _fetch() call, will contain the value "My Name":
var $rpNameRow1 = _fetch(_cell("routeplanListForm:routeDetailTable:0:rpName").innerHTML);
_click(_link("Navn", _in(_tableHeader("routeplanListForm:routeDetailTable:rpNameheader"))));
_wait(10000, _cell("routeplanListForm:routeDetailTable:0:rpName").innerHTML != $rpNameRow1);
the variable $rpNameRow1, after the _fetch() call, will contain the value "My Name":
var $rpNameRow1 = _fetch(_cell("routeplanListForm:routeDetailTable:0:rpName").innerHTML);
_click(_link("Navn", _in(_tableHeader("routeplanListForm:routeDetailTable:rpNameheader"))));
_wait(10000, _cell("routeplanListForm:routeDetailTable:0:rpName").innerHTML != $rpNameRow1);
sahi - how to get/fetch html text (textbox) input tag value
to get a textbox's value use .value
the variable $street is sent in with a value of "My Street 1":
_setValue(_textbox("editTAParty:street"), $street);
_wait(10000, _textbox("editTAParty:street").value == $street);
the variable $street is sent in with a value of "My Street 1":
_setValue(_textbox("editTAParty:street"), $street);
_wait(10000, _textbox("editTAParty:street").value == $street);
sahi - how to get/fetch html select input tag selected value and/or selected index number
to get a select list's selected index use .options.selectedIndex
UPDATE 20130902: .value didn't seem to work
if you want the selected option's value (label) use.value _getSelectedText(_select("editTAParty:role"))
which will give you the label text as it is seen in the browser, e.g.: "Despatch"
the variable $role is sent in with a value of 1:
_setSelected(_select("editTAParty:role"), $role);
_wait(10000, _select("editTAParty:role").options.selectedIndex == $role);
so if your code isn't using index numbers for setting the select, then use _getSelectedText instead:
_wait(10000, _getSelectedText(_select("editTAParty:role")) == $role);
UPDATE 20130902: .value didn't seem to work
if you want the selected option's value (label) use
which will give you the label text as it is seen in the browser, e.g.: "Despatch"
the variable $role is sent in with a value of 1:
_setSelected(_select("editTAParty:role"), $role);
_wait(10000, _select("editTAParty:role").options.selectedIndex == $role);
so if your code isn't using index numbers for setting the select, then use _getSelectedText instead:
_wait(10000, _getSelectedText(_select("editTAParty:role")) == $role);
sahi - use "wait" ( _wait ) to make your scripts *faster*
yes it sounds odd, but using _wait appropriately can actually make your scripts run faster, without having to worry whether any script command got skipped because something happened too fast (e.g. maybe because of ajax?) :)
i've found that if i don't insert _wait calls in sahi scripts, then sometimes certain operations get skipped, so my code used to consist of some guesstimated wait periods for certain operations, like this:
_setValue(_textbox("editTAParty:contact"), $email);
_wait(500);
_setSelected(_select("editTAParty:Party_languageIN"), $language);
_wait(500);
but if you use the advanced _wait functionality, then nothing will get skipped and your scripts will run as fast as possible. here's an example:
_setValue(_textbox("editTAParty:contact"), $email);
_wait(10000, _textbox("editTAParty:contact").value == $email);
_setSelected(_select("editTAParty:Party_languageIN"), $language);
_wait(10000, _select("editTAParty:Party_languageIN").options.selectedIndex == $language);
basically, these wait calls mean to proceed with execution of the next step immediately as soon as the condition is fulfilled (or after 10 seconds--whichever comes first).
10000 means 10 seconds (10000 milliseconds). i set a high number since i don't anticipate any operation in the app that i'm testing to ever taking longer than 10 seconds.
UPDATE 20130902
just tested a full implementation of this on a script with 320 steps and reduced the run time from 7:30 to 1:47 :)
i've found that if i don't insert _wait calls in sahi scripts, then sometimes certain operations get skipped, so my code used to consist of some guesstimated wait periods for certain operations, like this:
_setValue(_textbox("editTAParty:contact"), $email);
_wait(500);
_setSelected(_select("editTAParty:Party_languageIN"), $language);
_wait(500);
but if you use the advanced _wait functionality, then nothing will get skipped and your scripts will run as fast as possible. here's an example:
_setValue(_textbox("editTAParty:contact"), $email);
_wait(10000, _textbox("editTAParty:contact").value == $email);
_setSelected(_select("editTAParty:Party_languageIN"), $language);
_wait(10000, _select("editTAParty:Party_languageIN").options.selectedIndex == $language);
basically, these wait calls mean to proceed with execution of the next step immediately as soon as the condition is fulfilled (or after 10 seconds--whichever comes first).
10000 means 10 seconds (10000 milliseconds). i set a high number since i don't anticipate any operation in the app that i'm testing to ever taking longer than 10 seconds.
UPDATE 20130902
just tested a full implementation of this on a script with 320 steps and reduced the run time from 7:30 to 1:47 :)
sahi - how to print javascript timestamp date and time in console
var $now = new Date().getFullYear() + "." + new Date().getMonth() + "." + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds() + "." + new Date().getMilliseconds();
_debug($now);
In the grey "Sahi Controller" console you'll see something like this:
_debug("2013.7.30 12:1:20.777");
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.
#############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.
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
#######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
Subscribe to:
Posts (Atom)



