I am using selenium to test number of web pages in one test suite. is there any way of parameterizing the urls? I tried doing it using javascript file, like, added url in js file, and used that variable in href tag.
Use below code for same with js file which include
var URL=new Array("www.asd.com","www.asd.com","www.asdd.com","www.asdsa.com","www.asdda.com");
<tr>
<td>store</td>
<td>0</td>
<td>looptimes</td>
</tr>
<tr>
<td>while</td>
<td>storedVars.looptimes <= 1</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>alert("start")</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>URL[storedVars.looptimes]</td>
<td>URL</td>
</tr>
<tr>
<td>open</td>
<td>${URL} </td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars.looptimes++;}</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
Check this: http://saucelabs.com/blog/index.php/2011/01/selenium-resources-for-newbs-data-driven-testing-with-ide-xml/
Using this solution you can run each test case in a loop (each time using different url) then selenium will switch to next test case in test suite...
Test case would look like this:
loadTestData | file:///listofURLs.xml
while | !testdata.EOF()
nextTestData |
open | ${variableURL}
verifyTextPresent | sometext
verifyTextPresent | sometext
endWhile |
Related
I was given a task to retrieve a rather large number of PDF files from the clunky front end system of a former contractor. One must enter the file name, search, revalidate the file five or six times, then download the file.
I have written a script to do this in a loop, and so far, it's gotten the job done. However, if the file isn't found, it spits you to a new page, where it displays an error. You must then go back one page, and resume.
My issue is that I can't quite find a way to tell Selenium IDE "if you see this error, go back one page and resume" or "if the page changes, go back one page and resume."
Is it possible for Selenium IDE to follow an If command like this?
I have downloaded and installed all of the relevant plugins.
My script is as follows:
<!--Begin loop-->
<tr>
<td>loadTestData</td>
<td>file://C:\[[the file path]]\test_data.xml</td>
<td></td>
</tr>
<tr>
<td>while</td>
<td>!testdata.EOF()</td>
<td></td>
</tr>
<tr>
<td>nextTestData</td>
<td></td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>bizcase_filename=${bizcase_filename}</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=srch</td>
<td>${bizcase_filename}</td>
</tr>
<!--Begin revalidation (5 times)-->
<tr>
<td>click</td>
<td>css=input.button</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=td > img</td>
<td></td>
</tr>
<tr>
<td>select</td>
<td>id=action</td>
<td>label=Revalidate</td>
</tr>
<tr>
<td>click</td>
<td>//input[#value='Run']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pbStop</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=td > img</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[#value='Run']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pbStop</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=td > img</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[#value='Run']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pbStop</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=td > img</td>
<td></td>
</tr>
<!--End revalidation, retrieve file-->
<tr>
<td>click</td>
<td>//td[5]/a</td>
<td></td>
</tr>
<!--End loop-->
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
Test_data.xml, where I store all the file names, looks like this:
<testdata>
<test bizcase_filename="filename 1" />
<test bizcase_filename="filename 2" />
<test bizcase_filename="filename 3" />
</testdata>
You can use build in function called storeElementPresent
For example:
storeElementPresent id="error" x
And now, object "error" is stored in variable x.
Then you can call it with gotoIf function available from goto_sel_ide extension.
Example:
gotoIf ${x}==true errorVisible
gotoIf ${x}==false errorNotVisible
label errorVisible
goto tryAgain //tryAgain is a label set in right place
label errorNotVisible
goto Continue
label Continue
I hope you get the point. You can also use "if" statement by javascript.
Example (not related to your code):
storeElementPresent id=gbqfbb x /
click javascript{if(storedVars['x'] == true){this.browserbot.findElement('id=gbqfbb').click();}}
Hope it helps!
I need to type text in a field only if it is blank,if it has value proceed to next.
How to verify if field(id=Status) is empty then type a text"itemtoExpire" else continue with click id=submit button
Any suggestions using verify, gotoif, labels.
I am using selenium IDE
You may need to use the runScript command in Selenium IDE.
<tr>
<td>runScript</td>
<td>var val = document.getElementById('Status').value; if (val == '') { document.getElementById('Status').value = "itemtoExpire"; }</td>
<td></td>
</tr>
First you would require Selenium Flow Control to test conditions then use
type | id=input_id_or_selector | value_to_time
After the downloading of the plugin Selenium IDE: Flow Control try these commands in Selenium IDE that i think will work for your scenario.
<tr>
<td>storeText</td>
<td>id=Status</td>
<td>text</td>
</tr>
<tr>
<td>gotoIf</td>
<td>'${text}'!=''</td>
<td>submit</td>
</tr>
<tr>
<td>type</td>
<td>id=Status</td>
<td>itemtoExpire</td>
</tr>
<tr>
<td>goto</td>
<td>end</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>submit</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=submit</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>end</td>
<td></td>
</tr>
I'm new to gotoif condition in SeleniumIDE.
Trying to use it to test this scenario in the same test:
If page displays "test" icon, then click Launch and skip next step.
If page doesn't display "test" icon, then proceed to next step.
If You allways have pictire (but diffrent) in this place, You can get Xpath and get scr atribue of this picture:
<tr>
<td>storeAttribute</td>
<td>//body/div/img#src</td>
<td>urladress</td>
</tr>
<tr>
<td>gotoIf</td>
<td>'${urladress}'!= 'http://mypage.com/img/test.ico'</td>
<td>marker1</td>
</tr>
<tr>
<td>echo</td>
<td>Here commands for this picture</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>marker1</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>'${urladress}'== 'http://mypage.com/img/test.ico'</td>
<td>marker2</td>
</tr>
<tr>
<td>echo</td>
<td>Here commands without this picture</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>marker2</td>
<td></td>
</tr>
If it do not work you can use javascript function:
<tr>
<td>storeBodyText</td>
<td>body</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>javascript{storedVars['body'].search('test.ico')}</td>
<td>result</td>
</tr>
<tr>
<td>gotoIf</td>
<td>${result}==-1</td>
<td>marker1</td>
</tr>
<tr>
<td>echo</td>
<td>Here commands for this picture</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>marker1</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>${result}!=-1</td>
<td>marker2</td>
</tr>
<tr>
<td>echo</td>
<td>Here commands without this picture</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>marker2</td>
<td></td>
</tr>
I made a test which is working in newer or older firefox versions, slower or faster internet connection (at least I say that internet of my virtual machine in vmware is slow), but something and I don't know what causes a failure after typeKeys command in another computer. Somehow text is not written in the TinyMCE editor and therefore assertion fails.
Can anyone tell me what could cause such a thing or maybe there are incompatible commands?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://tinymce.com" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>http://tinymce.com/tryit</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>15000</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=demo_tab</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>id=content_ifr</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>id=content_ifr</td>
<td></td>
</tr>
<tr>
<td>focus</td>
<td>//body[#id='tinymce']</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//body[#id='tinymce']</td>
<td>(1,1)</td>
</tr>
<tr>
<td>typeKeys</td>
<td>//body[#id='tinymce']</td>
<td>writing something in this silly form</td>
</tr>
<tr>
<td>fireEvent</td>
<td>//body[#id='tinymce']</td>
<td>blur</td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>writing something</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>relative=parent</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=submitbtn</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=submitbtn</td>
<td></td>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>Post dump</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>HTML output from post</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>writing something</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Don't hesitate to ask if I wasn't clear enough.
Thanks for replies in advance.
Try using
Command | runScript
Target | tinyMCE.get('text_area_id_not_iframe_id').setContent('Your text')
Which will work on specific tinyMCE's or if you have multiple tinyMCEs on one page
Otherwise if you only have one tinyMCE, runScript | tinyMCE.activeEditor.setContent('Your text')
Here's what's working for me, essentially, by selecting the frame (others have suggested this), then the click and focus commands will make it the active editor, allowing the sendKeys command to work. In this example, I'm passing a variable to the editor as well as saving the iframe TinyMCE creates as a variable. For instances where multiple, I'm looping through them based on the ${frame} variable.
<
tr>
<td>selectWindow</td>
<td>null</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>xpath=//*[contains (#id, '${frame}')]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=//*[contains (#id, 'tinymce')]</td>
<td></td>
</tr>
<tr>
<td>focus</td>
<td>xpath=//*[contains (#id, 'tinymce')]</td>
<td></td>
</tr>
<tr>
<td>sendKeys</td>
<td>xpath=//*[contains (#id, 'tinymce')]</td>
<td>${date} ${frame}</td>
</tr>
For example:
<tr>
<td>storeEval</td>
<td>a_string</td>
<td>my_var</td>
</tr>
<tr>
<td>verifyElementPresent</td>
<td>css=#some_id[some_value='<my_var>']</td>
<td></td>
</tr>
css=#some_id[some_value='${my_var}']