Selenium IDE and CKEditor - selenium

I want to cleanup some HTML in a database using CKEditor's cleanup process. I need it to use this exact cleanup algorithm for reasons that are beyond the scope of this question. Submitting an existing form works perfectly, however there are many rows in the table, making for a tiresome process if done manually.
The solution I came up with was to generate a Selenium IDE test case that simply loads the page then submits the form for each record in the database.
The problem is that when Selenium IDE saves the data it does not seem to apply CKEditor's HTML cleanup algorithm.
For example...
I have the following in my database (loaded into CKEditor) when the form is loaded:
<p>
Hello World
</p>
When I press save on the form, the following is the result in my database:
<p>Hello World</p>
When I run a Selenium IDE script to load the page and submit the form, however the HTML remains unchanged (the cleanup did not occur).
Here is an example of my selenium script for a single form:
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr>
<td rowspan="1" colspan="3">selenium ckeditor</td>
</tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/form.php?id=1</td>
<td></td>
</tr>
<tr>
<td>fireEventAndWait</td>
<td>id=form</td>
<td>submit</td>
</tr>
</tbody>
</table>
It seems some JS event is not being triggered, but I am not sure which event it could be.

Pausing for a second after loading the page makes it work. I guess selenium was submitting before ckeditor kicked in.
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr>
<td rowspan="1" colspan="3">selenium ckeditor</td>
</tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/form.php?id=1</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>fireEventAndWait</td>
<td>id=form</td>
<td>submit</td>
</tr>
</tbody>
</table>

Related

Border collapse causes mobile browsers to show unwanted borders

Consider the following table in html:
<table style="border-collapse:collapse">
<tr>
<td style="height:25px"></td>
<td style="width:150px;border:1px solid #aaa;"></td>
<td rowspan="4" style="width:10px;"></td>
<td style="width:150px;border:1px solid #aaa;"></td>
</tr>
<tr>
<td style="height:25px"></td>
<td></td>
<td></td>
</tr>
<tr>
<td style="height:25px"></td>
<td></td>
<td></td>
</tr>
</table>
This table renders just fine on every desktop web browser I've tried, but on the mobile web browsers I've tried (iOS: Safari and Chrome), the middle column extends the left and right borders to the bottom. It looks like this:
Is there any way to get around this without, ideally without changing border-collapse or the middle column's rowspan?

error Element id not found on Selenium IDE

I've been recorded a test case using Selenium IDE and I've encountered an error Element id=XXX not found. Tried using clickAndWait and still nothing happens. Scenario is that I'm on Page 1 and clicked on view then Page 2 appears. Need to check on actions on Page 2. When tried refresh it only refresh Page 1 instead of Page 2.
<tr>
<td>open</td>
<td>/index.php/admin/lead/myLeads</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=search_company_name</td>
<td>J02217 GMBH Test 1</td>
</tr>
<tr>
<td>click</td>
<td>css=span.glyphicon.glyphicon-search</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.fa.fa-info-circle</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.glyphicon.glyphicon-remove</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>id=btn-add-file</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=btn-add-file</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Close</td>
<td></td>
Add two things to your script. At the beginning
<tr>
<td>setTimeout</td>
<td>60000</td>
<td>Wait 60 seconds for the page</td>
</tr>
And after the click that launches page two
<tr>
<td>waitForPageToLoad</td>
<td>60000</td>
<td>Wait up to one minute</td>
</tr>
Welcome to Selenium testing. You should try to outgrow IDE as quickly as possible. IDE is training wheels. Move to WebDriver as soon as can. There are plenty of tutorials available.

Selenium IDE checkbox checked identification

I am learning how to use Selenium IDE and it's going pretty well I think, but now I can't seems to find how I can check the checkbox on that Page.
https://www.otelo.de/warenkorb.html?id=-1
I can't seem to find out how to see if the checkbox is checked
The only thing selenium ide is showing me is id=mnp if I try to record it
Can you please help me and tell me what am I doing wrong?
thx you very much!
I have used SelBlocks Plugin for If-Else You can use storeChecked to store the state of checkbox
storeChecked(locator, variableName)
Generated from isChecked(locator)
Arguments:
locator - an element locator pointing to a checkbox or radio button
Returns:
true if the checkbox is checked, false otherwise
Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>IfElse</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">IfElse</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>https://www.otelo.de/warenkorb.html?id=-1</td>
<td></td>
</tr>
<tr>
<td>storeChecked</td>
<td>id=mnp</td>
<td>state</td>
</tr>
<tr>
<td>if</td>
<td>${state}==false</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=mnp</td>
<td></td>
</tr>
<tr>
<td>endIf</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>

how to do if else in Selenium?

I have recorded the log-in into some page with FireFox Plugin Selenium IDE. The recorded result looks like this:
..
....
</thead><tbody>
<tr>
<td>open</td>
<td>/libs/cq/core/content/welcome.html</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/libs/cq/core/content/login.html?resource=%2Fcontent%2Fvrbp%2Fde%2Fpage%2home.html&$$login$$=%24%24login%24%24</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=input-submit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=input-submit</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=searchbox__form-text</td>
<td></td>
</tr>
...
.....
I have saved this Test-case and started it with Selenium IDE. It works fine. It opens the welcome page and then opens the login page and then do the log in.
The problem is now in the case if I am already loged in the page. the Test process hangs on the line ClickAndWait. It does not find the login fields, because I am already loged in.
My Question is: How to tell that it should ignore this step, if I am already loged in?
Is there any unique element you can look at from the log-in page? For example, password and username fields. If they are visible, do a log in, if they are not, you are already logged in.
Hope it helps.
First of all you have to download the plugin flow control for the selenium ide.(https://addons.mozilla.org/en-US/firefox/addon/flow-control/)
Then you have to add some commands to your code to check if the button login exist. So the final code should look like this:
</thead><tbody>
<tr>
<td>open</td>
<td>/libs/cq/core/content/welcome.html</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/libs/cq/core/content/login.html?resource=%2Fcontent%2Fvrbp%2Fde%2Fpage%2home.html&$$login$$=%24%24login%24%24</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=input-submit</td>
<td>present</td>
</tr>
<tr>
<td>gotoIf</td>
<td>present!=true</td>
<td>label1</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=input-submit</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>label1</td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=searchbox__form-text</td>
<td></td>
</tr>

Selenium IDE testing all links

I'm trying to use Selenium IDE to test a web app. On one page, there are several links which trigger modal windows. I'd like to test ALL the links on the page to ensure that ALL cause modals to pop up.
Each link has a class "modal" so I thought I could just change the target value in IDE css=a.modal but that finds only the first link.
I've found a few solutions but they use Selenium RC with Java/Python and those can't be directly translated to the IDE.
I understand the IDE is not as powerful but I'm setting this up for a non-programmer to use and up till now, it's been really simple for them.
i had to read up a lot and i want to thank #ohaal and #aleh for their inputs. i used their suggested links as well as some more external reading to reach the solution like so:
<tr>
<td>open</td>
<td>/logout</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Forum</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//p[3]/span/a[contains(#class, 'modal')]</td>
<td>users</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>i</td>
</tr>
<tr>
<td>while</td>
<td>storedVars.i<=storedVars.users</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//descendant::a[contains(#class, 'modal')][${i}]</td>
<td></td>
</tr>
<tr>
<td>waitForText</td>
<td>css=h2</td>
<td>You are not logged in</td>
</tr>
<tr>
<td>click</td>
<td>css=#cross_button > a > img</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars.i++}</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
i'm not selecting any one answer as all of them contributed to the final solution.
Use a while loop, and this XPath expression as a locator: //a[contains(#class, 'modal')]
//a[contains(#class, 'modal')][1], //a[contains(#class, 'modal')][2] and so on should point to the links you're after.
See this link for more information on how to do while loops in Selenium IDE if you are unfamiliar with it.
Try this (you have to download this extension):
<tr>
<td>storeCssCount</td>
<td>css=a.modal</td>
<td>links</td>
</tr>
<tr>
<td>store</td>
<td>0</td>
<td>i</td>
</tr>
<tr>
<td>label</td>
<td>l1</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars.i++</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//descendant::a[contains(#class, 'modal')][${i}]</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>--storedVars.links</td>
<td>l1</td>
</tr>
Insert your assertions and probably pop-ups closings before last command (gotoIf).