Showing posts with label Selenium IDE. Show all posts
Showing posts with label Selenium IDE. Show all posts

Tuesday, March 5, 2013

Selenium IDE - How get Current - date, month, year & time through script

Selenium IDE - How get Current - date, month, year & time through script


There are many ways like as below:

1.

Current Time - javascript{(new Date().getHours()+" : " + new Date().getMinutes() + " : " + new Date().getSeconds())}

Current year - javascript{(new Date()).getFullYear()}

Current Month - javascript{(new Date().getMonth()) + 1}

Current date - javascript{(new Date().getDate().toString())}



2. 


<tr> 
        <td>storeEval</td> 
        <td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1)) 
+'-'+d.getFullYear();</td> 
        <td>date2</td> 
</tr> 
<tr> 
        <td>echo</td> 
        <td>${date2}</td> 
        <td></td> 
</tr> 




3. 

Friday, March 1, 2013

Selenium IDE - Find & Replace text in url

Selenium IDE - Find & Replace text in url


Steps:

1. First store current url in to any variable.


<tr>
<td>storeLocation</td>
<td>url1</td>
<td></td>
</tr>


2. Next using replace function, replace the word - pdfreader with epub reader in the url & again store in different variable.


<tr>
<td>storeEval</td>
<td>&quot;${url1}&quot;.replace(&quot;pdfreader&quot;,&quot;epubreader&quot;)</td>
<td>url2</td>
</tr>

Tuesday, August 14, 2012

Selenium IDE Tip - Continue if only element is present else not

Selenium IDE Tip - Continue if only element is present else not


In the following code, first check element is present or not.

If not present, then exist from the loop to the label - exit, else continue the commands - verify Text

This really helps when we want to run specific TC or not??


<tr>
<td>storeElementPresent</td>
<td>${category_header_obj}</td>
<td>present</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['present']==false</td>
<td>exit</td>
</tr>
<tr>
<td>verifyText</td>
<td>${category_header_obj}</td>
<td>Categories</td>
</tr>

Monday, August 13, 2012

How to use if else condition in selenium ide

How to use if ...else condition in selenium ide ???


1. Download the below file & store in option > file list.
2. Open the selenium ide

one example is shown below

Example:
store     | 10                  | x
gotolabel | target1             |
getEval   | alert("Skip This"); |
label     | target1             |
store     | 14                  | y
gotoIf    | ${y} > ${x}         | target2
getEval   | alert("Skip This"); |
label     | target2             |
while     | storedVars['x'] <= storedVars['y'] |
getEval   | storedVars['x'] = ${x} + 1; |
endWhile  |                     |
getEval   | alert("Finished");  |
The following commands are available:
goto       gotoAndWait        gotoIf     gotoIfAndWait
gotolabel  gotolabelAndWait   while      whileAndWait
endWhile   endWhileAndWait
Download the file 

How to use - String functions ??



1. trim()


<tr>
<td>storeEval</td>
<td>"${deliverych1_price_val}".trim()</td>
<td>deliverych1_price_val</td>
</tr>

Thursday, June 23, 2011

Selenium - How to find string exists in the browser url or not ??





/**********************************************************
     Function Name      : LocationTextPresent
     Arguments             : text
     Description             : This function checks whether text is present in URL or not.
     Author                    : Sara ,Bangalore
/*********************************************************/
Selenium.prototype.getLocationTextPresent = function(text) {

     var element = this.browserbot.getCurrentWindow().location;

             var patternMatcher = new PatternMatcher(text);
    if (patternMatcher.strategy == PatternMatcher.strategies.glob) {
            if (text.indexOf("glob:")==0) {
                    text = text.substring("glob:".length); // strip off "glob:"
                }
        patternMatcher.matcher = new PatternMatcher.strategies.globContains(text);
    }
    else if (patternMatcher.strategy == PatternMatcher.strategies.exact) {
                text = text.substring("exact:".length); // strip off "exact:"
        return element.indexOf(text) != -1;
    }
    return patternMatcher.matches(element);
};

<tr>
            <td>verifyLocationTextPresent</td>
            <td>ruby</td>
            <td>true</td>
</tr>

Ex: 


<tr>
            <td>verifyLocationTextPresent</td>
            <td>sara</td>
            <td>true</td>
</tr>

Friday, June 17, 2011

Selenium IDE - How to read table & append the table content into a single variable


It is simple.  Try the below code:

 1. This function locates the table in a html page.
 2. Finds no. of rows in a table.
 3. Reads each row data & appends into single variable.
 4. Returns the variable.



Selenium.prototype.getSaraTableAppend = function(tableName) {

try
{

    var table = this.browserbot.findElement(tableName);
             var rows = table.rows.length;
  
                         var apptxt = 0;

                for (var i = 2; i < rows ; i++)
                {
                                                               
                        var celltxt  = getText(table.rows[i].cells[0]);
                        apptxt = apptxt + celltxt;
                                                                       
                }
               
               return apptxt;

}
catch (e)
{
        throw new SeleniumError("Threw an exception!" + e.message);
}

};

 Then call this function in Selenium IDE as,

<tr>
            <td>storeSaraTableAppend</td>
            <td>css=table</td>
            <td>Result</td>
</tr>



Ex:

  Table is as below :
123
456
789
Abc
efg

Results contains data as: 0123456789Abcefg

Selenium IDE - How to Read table content & store as a Array


It is simple.  Try the below code:

1. This function locates the table in a html page.
2. Finds no. of rows in a table.
3. Reads each row data & stores in an array.
4. Returns the data in an array.

Selenium.prototype.getSaraTable = function(tableName) {
try
{
    var table = this.browserbot.findElement(tableName);
            var rows = table.rows.length;
            var TblArr = [];
                for (var i = 0; i < rows ; i++)
                {
                        var celltxt  = getText(table.rows[i].cells[0]);
                        TblArr.push(celltxt);
            }
                return TblArr;
}
catch (e)
{
        throw new SeleniumError("Threw an exception!" + e.message);
}

};


 Then call this function in Selenium IDE as,


<tr>
            <td>storeSaraTable</td>
            <td>css=table</td>
            <td>Result</td>
</tr>


Ex:

  Table is as below :

123
456
789
Abc
efg






           Results contains data as: 123,456,789,Abc,efg



Thursday, June 16, 2011

Useful functions / Helpful Question & Answers about Selenium

How to do this in Selenium ??

Find below some of the useful functions or Q & A:



1. How to clear or delete the cookies -  >> more 

2. Selenium IDE - How to Read table content & store as a Array - >> more

3. Selenium IDE - How to read table & append the table content into a single variable - >> more 

4. Selenium - How to find a given string or text is present in URL or not - >> more




Wednesday, June 15, 2011

How to clear or delete cookies in Selenium


How to delete a cookies in Selenium IDE

It is very much necessary to delete cookies in order to continue the script execution.

There 2 ways to clear

  1. Either clear the browser cache including cookies
  2. Else delete the cookie either by name or all.

Commands used for deleting cookies in Selenium are:

deleteAllVisibleCookies ( )
Calls deleteCookie with recurse=true on all cookies visible to the current page. As noted on the documentation for deleteCookie, recurse=true can be much slower than simply deleting the cookies using a known domain/path.

deleteCookie ( name,optionsString )
Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you need to delete it using the exact same path and domain that were used to create the cookie. If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also note that specifying a domain that isn't a subset of the current domain will usually fail. Since there's no way to discover at runtime the original path and domain of a given cookie, we've added an option called 'recurse' to try all sub-domains of the current domain with all paths that are a subset of the current path. Beware; this option can be slow. In big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain name and m is the number of slashes in the path.

Arguments:
1.name - the name of the cookie to be deleted

2. optionsString - options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.


Selenium IDE:


1.      Usage of deleteAllVisibleCookies ( )


<tr>
            <td>deleteAllVisibleCookies</td>
            <td></td>
            <td></td>
</tr>

2.      Usage of deletecookie

Get the specific cookie name you want to delete in FF -> Tools -> Options -> Privacy -> Cookies

Ex:

 Name : PREF
 Domain: .google.com
 Path: /


    <tr>
            <td>deleteCookie</td>
            <td>PREF</td>
            <td>“path=/”, domain=”.google.com”, “recurse=true”</td>
</tr>





Selenium RC

Using below user defined JAVA function

protected void deleteCookie(String cookieName)
{
String cookieDomain =
CTPropertiesManager.getProperty("site.properties", 

"site.cookie.domain");

try
{
//get all cookies
Cookie cookies[] = request.getCookies();

Cookie ctCookie=null;
if (cookies !=null)
{
for(int i=0; i<cookies.length; i++)
{
ctCookie=cookies[i];
if (ctCookie.getName().trim().equals(cookieName))
{
if ( cookieDomain != null )
{
ctCookie.setDomain(cookieDomain);
}

ctCookie.setPath("/ct");
ctCookie.setMaxAge(0);
response.addCookie(ctCookie);
}
}//end for
}//end if cookie
}//end try
catch(Exception e){
CTLogManager.log(e);
}
}//end deleteCookie()



Wednesday, May 4, 2011

Selenium IDE





It is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser.

1. Download & Install  - >> More

2. How to automate & run the tests - >> More

3. Using Selenium IDE - Learn to use Selenium IDE in just 2 Minutes! - See this video clip

4. How to do this <......> in Selenium IDE.   See here all the tips those were added - Selenium IDE Tips


Selenium IDE Plugins


1.   For FLEX application, Selenium has Flex plugins to support.
      click here

Thursday, March 17, 2011

Selenium User Extensions - How can i write ??



1. Find here how can we create our own user extension function.  Very nice one

   click here