I'm trying to replace " characters within text stored within a Selenium IDE test.
As an example I'm doing
<tr>
<td>storeText</td>
<td>id=request-header</td>
<td>variable1</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{'hi'.replace('i','a')}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>javascript{$variable1.replace('G','a')}</td>
<td></td>
</tr>
The first echo outputs 'ha' but the second results in an error.
Thanks
In javascript execution context you have to use the storedVars array to access stored variables:
<tr>
<td>echo</td>
<td>javascript{storedVars.variable1.replace('G','a')}</td>
<td></td>
</tr>
Related
I need to get data from a table in an EXTERNAL HTML file (on a different server) and store the data.
Is it possible to import a html file from a http URL to work with the data?
How can I read different rows and cols from external files?
I need to get the data, store it somehow (maybe JSON or an array?) so I can work with the data.
For Example:
<table id="table1" class="tg">
<tr>
<th>1A</th>
<th>1B</th>
<th>1C</th>
<th>1D</th>
</tr>
<tr>
<td>2A</td>
<td>2B</td>
<td>2C</td>
<td>2D</td>
</tr>
<tr>
<td>3A</td>
<td>3B</td>
<td>3C</td>
<td>3D</td>
</tr>
<tr>
<td>4A</td>
<td>4B</td>
<td>4C</td>
<td></td>
</tr>
<tr>
<td></td>
<td>5B</td>
<td>5C</td>
<td></td>
</tr>
<tr>
<td></td>
<td>6B</td>
<td></td>
<td></td>
</tr>
</table>
I Need to store the different colums like:
(1A,2A,3A,4A,)
(1B,2B,3B,4B,5B,6B)
(1C,2C,3C,4C)
(1D,2D,3D)
Thank you for your help :)
I'm trying to create a selenium script to log into a site with a username and password complete a task, log out then start over but with a multiple different username/passwords. Is it possible to get the script to use values from a text file or something?
<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>/common/oauth2/authorize?client_id/td>
<td></td>
</tr>
<tr>
<td>assertTitle</td>
<td>Sign in to your account</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=cred_userid_inputtext</td>
<td>example#example.com</td>
</tr>
<tr>
<td>click</td>
<td>id=cred_password_inputtext</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=cred_password_inputtext</td>
<td>password1</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=cred_sign_in_button</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ms-Icon--outlook</td>
<td></td>
</tr>
<tr>
<td>select</td>
<td>id=selTz</td>
<td>label=(UTC-08:00) Pacific Time (US & Canada)</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=span.signinTxt</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=(//button[#type='button'])[12]</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//button[#type='button'])[51]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//table[#id='use_another_account']/tbody/tr/td/table/tbody/tr[2]/td[2]/div</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Sure it is possible to read from an external source and run your automation test.
If you have a lot of credentials, I would recommend that you directly talk to the test database to retreive that data and then use it for your automation test. I don't know javascript or python but I'm sure that if you Google, you can find a solution on how to do this.
If this is too complex, then you might just prefer to read from a file like a .csv. Python or javascript will probably have some frameworks that you can use to read .csv files. Worst case scenario is you will have to write your own logic to read the file, which I'm sure already exists on the web.
Whatever method you choose, just use your code to read that entity, store the values in variables, and then apply those variables in your tests. Here is a sample of my test using C#. It runs through many 'accessionNumbers' that it reads from an external source.
[Test, TestCaseSource("GetDataList")]
[Property("PBI#", "35656")]
public void GivenPopupItemIsOpen_WhenTogglingPopup_ThenPopupOpensAndCloses(string accessionNumber)
{
var studentAssesmentPage = OpenAdminResetPageAndGoToBookletLocation(accessionNumber);
studentAssesmentPage.ShortTextPopup.OpenPopUp();
studentAssesmentPage.ShortTextPopup.ClosePopUp();
Assert.IsFalse(studentAssesmentPage.ShortTextPopup.IsPopUpOpen(), "The pop up did not close after trying to close the pop up");
}
I'm trying to just a jQuery function to show a table on a Django page. When I test the script on jsfiddle, it works great but it's not working on my Django site. Do I need to import something into Django to make it work?
This is what I have thus far:
html file:
<table class="panel">
<tr>
<td colspan=3 class="tblheader"><h1>Statistics</h1></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<button class="spoiler">Click for Spoilers</button>
javascript file:
$(document).ready(function() {
$('.spoiler').click(function() {
$('.panel').slideToggle('slow');
});
});
You should add reference to jquery script from your Django html template, for example
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
More information on jquery site
I want to create a JavaScript date using text I stored from my site.
This is what I tried:
<tr>
<td>storeValue</td>
<td>name=contract_additional_fields[agreement_created_date]</td>
<td>seleniumContractDateValue</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{Date.parse('${seleniumContractDateValue}')}</td>
<td></td>
</tr>
I also tried using nothing or "" in the parse but neither one worked.
Can anyone help me figure out how I use a stored variable as a parameter of a JavaScript command?
1.you access variables with "storedVars['seleniumContractDateValue']" in JavaScript.
2.Selenium won't store a JavaScript date object, so you will need to parse it into a string as well.
<tr>
<td>storeValue</td>
<td>name=contract_additional_fields[agreement_created_date]</td>
<td>seleniumContractDateValue</td>
</tr>
<tr>
<td>store</td>
<td>javascript{Date.parse(storedVars['seleniumContractDateValue'])}</td>
<td>seleniumContractDateValue</td>
</tr>
<tr>
<td>echo</td>
<td>${seleniumContractDateValue}</td>
<td></td>
</tr>
I'm trying set item in select using javascript (in variable I have date)
Here is how I'm trying set this item
<tr>
<td>select</td>
<td>Recent-Year</td>
<td>value=javascript{d=new Date();d.getYear()}</td>
</tr>
I get:
[error] Option with value 'javascript{d=new Date();d.getYear()}' not found
of cource when I'm trying by this:
<tr>
<td>select</td>
<td>Recent-Year</td>
<td>value=2011</td>
</tr>
it works.
What I must to change in this code to set this item?
EDIT
I don't want to split this command into few commands, because in another testcase I have stored variable birthday
<tr>
<td>storeEval</td>
<td>new Date('1966,09,16')</td>
<td>dateOfBirth</td>
</tr>
and I have 3 selects : Birth-Day, Birth-Month and Birth-Yearand I don't want to create 3 variables.
I want to set items in select like this:
<tr>
<td>select</td>
<td>Birth-Year</td>
<td>value =${dateOfBirth.getFullYear()}</td>
</tr>
Store the JavaScript evaluation first (using storeEval) and then use this variable as your option value:
<tr>
<td>storeEval</td>
<td>new Date().getYear()</td>
<td>varYear</td>
</tr>
<tr>
<td>select</td>
<td>Recent-Year</td>
<td>value=${varYear}</td>
</tr>
That should work
Update: In response to your edit: you can't use the value= with JavaScript but you can use the storedVars variable available in the JavaScript environment to create all the variables you need. For example, storedVars['myVar'] can be accessed directly through Selenium as ${myVar}. Below, I use verifyEval to run some JavaScript that will create all the variables I need.
<tr>
<td>storeEval</td>
<td>new Date()</td>
<td>myDate</td>
</tr>
<tr>
<td>verifyEval</td>
<td>var date=storedVars['myDate']; storedVars['day']=date.getDate(); storedVars['month']=date.getMonth(); storedVars['year']=date.getFullYear();</td>
<td></td>
</tr>
Then you can select the options based on:
<tr>
<td>select</td>
<td>Birth-Day</td>
<td>value=${day}</td>
</tr>
<tr>
<td>select</td>
<td>Birth-Month</td>
<td>value=${month}</td>
</tr>
<tr>
<td>select</td>
<td>Birth-Year</td>
<td>value=${year}</td>
</tr>
I know it's not the ideal solution, but it does help a bit since you can't do value=javascript{...} (not that I know of anyway but if anyone else knows otherwise then please say).