Monday, October 31, 2011

Google-wiki script without using UI-Elements

Google-wiki script without using UI-Elements ,Selenium Notes, Videos, Examples By.www.laxmiroy.blogspot.com/


Google-wiki script without using UI-Elements
Command       Target  Value
open    http://www.google.co.in/       
verifyElementPresent  logo    
type     q          wikipedia
click     btnG   
waitForElementPresent           nqsbq  
verifyElementPresent  nqsbq  
type     nqsbq   selenium
click     btnGNS          
waitForElementPresent           link=Selenium (software) - Wikipedia, the free encyclopedia           
verifyElementPresent  link=Selenium (software) - Wikipedia, the free encyclopedia           
click     link=Selenium (software) - Wikipedia, the free encyclopedia           
waitForElementPresent           //div[@id='p-logo']/a  
verifyTitle       Selenium (software) - Wikipedia, the free encyclopedia       
verifyElementPresent  //div[@id='p-logo']/a  


Same script with UI-Elements
Command       Target  Value
open    http://www.google.co.in/       
verifyElementPresent  ui=googleSearch_page::theBigGoogleLogo()           
type     ui=googleSearch_page::search_Textbox()      wikipedia
click     ui=googleSearch_page::search_button()        
waitForElementPresent           ui=googleSearch_page::searchwikipedia_textbox()  
verifyElementPresent  ui=googleSearch_page::searchwikipedia_textbox()  
type     ui=googleSearch_page::searchwikipedia_textbox()   selenium
click     ui=googleSearch_page::searchwikipedia_button()    
waitForElementPresent           ui=googleSearch_page::seleniumSearchResult_Link()          
verifyElementPresent  ui=googleSearch_page::seleniumSearchResult_Link()          
clickAndWait  ui=googleSearch_page::seleniumSearchResult_Link()          
waitForElementPresent           ui=wikipediaArticle_page::wikipediaGlobe_image()
verifyTitle       Selenium (software) - Wikipedia, the free encyclopedia       
verifyElementPresent  ui=wikipediaArticle_page::wikipediaGlobe_image()

The UI-Element map file used to for this script is as follows:

var myMap = new UIMap();



myMap.addPageset({

name: 'googleSearch_page'

, description: 'google main search page'

, pathRegexp: '.*'

});



myMap.addElement('googleSearch_page', {

name: 'theBigGoogleLogo'

, description: 'the Google logo visible on the main google search page'

, locator: "logo"

}

);



myMap.addElement('googleSearch_page', {

name: 'search_Textbox'

, description: 'the Google search textbox on google search page'

, locator: "q"

}

);



myMap.addElement('googleSearch_page', {

name: 'search_button'

, description: 'the Google search button with "Google Search" label on google search page'

, locator: "btnG"

}

);



myMap.addElement('googleSearch_page', {

name: 'firstSearchResultItem_Link'

, description: 'the first item in the search result list'

, locator: "//ol[@id='rso']/li[1]/h3/a/em"

}

);



myMap.addElement('googleSearch_page', {

name: 'searchwikipedia_textbox'

, description: 'search wikipedia text box below the google search result item'

, locator: "nqsbq"

}

);



myMap.addElement('googleSearch_page', {

name: 'searchwikipedia_button'

, description: 'Search Wikipedia.org button'

, locator: "btnGNS"

}

);



myMap.addElement('googleSearch_page', {

name: 'seleniumSearchResult_Link'

, description: 'search result link to selenium article in wikipedia'

, locator:"link=Selenium (software) - Wikipedia, the free encyclopedia"

}

);



myMap.addElement('googleSearch_page', {

name: 'wikipediaSeleniumPage_title'

, description: 'Title of th wiki page for selenium'

, locator:"Selenium (software) - Wikipedia, the free encyclopedia"

}

);



myMap.addPageset({

name: 'wikipediaArticle_page'

, description: 'wikipedia'

, pathRegexp: 'wiki/Selenium.*'

});



myMap.addElement('wikipediaArticle_page', {

name: 'wikipediaGlobe_image'

, description: 'Wikipedia, the free encyclopedia globe image'

, locator:"//div[@id='p-logo']/a"

}

);

This UI-MAP file has to be created manually. It looks quite complex but believe me it becomes a lot easier ones you start using it regularly. This map file is a JavaScript file with extention '.js' and has to be attached to Selenium IDE from Options->Options->Selenium Core Extentions.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfo6SNWr-EWRkgiZ8I3x3GDgjqTgBnTUvx_HGJXP0flkOmMTsumq9cMcG32X3ov57GLr1Fvhbzs41fdO7o8ik74Mk25BB8OCW19Em8Pjkk0ww7HlxcecVRyL8Fyiujb1Mkj4pq8ecZmLQ/s400/uimapFileAttachedToIDE.JPG

Try this example out yourself. Just copy the entire html table above and paste it into the IDE (except the header row). Similarly copy ui-map file into notepad and save it as 'uiMapGoogle.js'. Now attach this file as a user extension in IDE options. You will be able to run the ui-element version of the script at this point. Also for any recording you do on the element mentioned in the map file you will see UI-Element based locators recorded in the IDE window. Also remember that after making any changes the map file the changes will take effect only after you close-reopen the IDE window. 


No comments:

Post a Comment