Saturday, October 6, 2012

0 Introduction to javascript and Selenium-IDE.js

The core of Selenium IDE is developed in JavaScript. All the available commands in Selenium IDE are developed using JavaScript. We can also develop our own custom commands in Selenium IDE with help JavaScript and user extensions, which will be discussed shortly.

The best place to learn JavaScript is w3schools.com. I learned JavaScript from the same location and I made custom notes from my learning. You can download it from DownloadMyNotes. You can practice examples mentioned in MyNotes in editors like EditPlus or even a text file saved with extension ".html"

I request everyone to first learn JavaScript from sources mentioned above and then proceed further with the rest of the tutorial.

First look at Selenium core - Selenium-IDE.js

I asserted that "All the available commands in Selenium IDE are developed using JavaScript". Yes, that's true. Please have a look at the code Selenium-IDE.js and come back to this module. Don't worry if you don't understand the code. The purpose of this visit is to just have a first look at JavaScript code of functions we are using in Selenium IDE. Try to just skim through the code.

Now that we saw Selenium IDE's core, let us examine JavaScript code for couple of functions that we already know.

Function: Type
Purpose: Sets the value of an input field.
Those who completed module: Selenese Commands are aware that we use this function to enter some text into any input field on a webpage.
Function Definition from SeleniumIDE.js file
  Explanation:
1. Selenium.prototype.doType: This mean that we are writing a function called "Type"
2. function(locator, newText): Here locator and newText form the parameters to the function Type. So whom so ever created this function, they wanted users of this function to pass in two parameters to the function. Recall that when we used this function inside Selenium IDE, we passed in two parameters that include XPath as Target and Value as. text to be entered.
3. JavaScript code:  This is nothing but code between the flower  brasses "{" and "}" that defines the purpose of the function. In this case to type text into passed in element locator.

Don't worry much about code. Try to understand the structure because we will create our own functions shortly and to do so, you should be familiar with the structure. Get yourself familiar with structure of the function looking at below examples. Try to identify function name, required parameters and function definition from below examples.

Function: SelectWindow
Purpose: Selects a window based on passed in windows name







Function: Select
Purpose: Selects a value from the drop down element

Function: Goback
Purpose: Simulates browser back button
Please note that this function does not accept any parameters

Similar to above examples, we have JavaScript code for every function we use at Selenium IDE inside Selenium-IDE.js. Visit this file once again and get your self familiar with structure of the function before proceeding to next module. I hope you enjoyed reading this post. I will be glad to read your valuable comments. See you again in the next module. Thank you.

0 comments:

Post a Comment

 

QuestionSelenium Copyright @Shiva Krishna