How to submit form in loop in Selenium IDE - selenium

I'm using Selenium IDE in Firefox and submiting a form. The problem is that the form can be sucesfull or unsuccesfull (random). When it's unsuccesfull it will show and error message (AJAX) and I need to try to submit the form again.
I would like to write a test which will be submiting the form until it will redirect me to success page (text present).
Can someone helps me with this? I didn't play with Selenium this way yet.

Here is an extension that adds full-fledged looping, conditional execution, and callable functions to Selenium IDE: SelBlocks.
Dave Hunt mentioned flowControl, which is a possibility. But besides higher-level functionality, a significant difference is that SelBlocks takes eval expressions (regular javascript), which might make checking AJAX status a bit easier.

You can use selenium extension goto_sel_ide. This will enable flow control commands.
Then you can use while command, and with help of this you can run script till you get success message.
Let me know whether it is working for you or not

Related

is there some way to get all the invalid locators in selenium automation?

I have many locators and if any one among them fails the program fails, We can not get a list of locators failed.
is there some way/method to get all the invalid locators in selenium automation???
The easy way (in case of you're using a framework and the code is well structured) :
Add the action performed on any locator into a try-catch block and store locator's name into a file, log it into console etc (it's up to you). In this way, you can follow up and update them after.
The manual way:
Go manually trough all your locators and look after them in HTML code in browser's console
The less painful manual way:
Execute all tests, and from your report (if you're using any reporting tool) or from console, collect and check each locator .
Now, if you're just doing a clean-up, I recommend the first approach. If you're facing issues with the locators, flaky situations, I recommend creating dynamic locators (xpath or css).

Getting web driver logging information running Protractor

So I am in the process of writing some tests with Protractor for an angular application I am working on. I ran into an issue where a test was failing because I tried to click on an element that while existed, it could not be clicked because another element was above it and it was receiving the click event. The error was just that true not does equal false which gives no insight to the real underlaying issue. I have run into this issue many times with other tests so I knew pretty quickly was the issue was but if I had not experienced this before, I don't know how long it would take me to figure it out.
I am 99% sure that when you send a click event with the JSON Wire Protocol that if the element does receive the click, there will be a message relating to that in it's response. Is there any way with Protractor to get the JSON Wire Protocol responses on to the screen when running the tests or at least get the responses captured in a file or something?
Assuming you are using Jasmine (the default) i suggest you start using explicit waits for elements to be present and visible before interacting with them like in your example.
I'm using this custom mathers.
Then:
var theElementFinder = $('#someElm');
expect(theElementFinder).toBePresentAndDisplayed();
Regarding
a way with Protractor to get the JSON Wire Protocol responses
You already see selenium errors in your Terminal / Console output.

PhantomJS, but not headless?

Is there a way to get a realtime view of what PhantomJS (or similar) is rendering?
I would like to develop my automation script while interacting with (or at least seeing a screencap of) the page it's targeted to.
No, there is no such thing. SlimerJS has the same API as PhantomJS, but runs the Gecko engine. You can see directly what is going on and run it headlessly with xvfb-run.
You will not be able to interact with it. You may want to use a screengrabber to record a video of the interaction when the tests are long and you don't want to run the test suite again if you didn't catch the problem in the test case.
The obvious way to debug PhantomJS scripts is to render many screenshots using page.render() and logging some objects to the console with
console.log(JSON.stringify(yourObj, undefined, 4));
with nice formatting.
Solution we use is an automatic screenshoting in case of exceptions, phantomJs will render the current page into a file that you can exam later .
That's for test execution phase.
When you writing the tests, just keep additional window open ("normal browser") with the application you trying to test and design the test according to it.
When the design is done, execute the test with phantomJS.
My Suggestion is to use logging alongside.
http://casperjs.org/
CasperJS is an open source navigation scripting & testing utility written in Javascript for the PhantomJS WebKit headless browser and SlimerJS (Gecko). It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:
defining & ordering browsing navigation steps
filling & submitting forms
clicking & following links
capturing screenshots of a page (or part of it)
testing remote DOM
logging events
downloading resources, including binary ones
writing functional test suites, saving results as JUnit XML
scraping Web contents
The solution to this problem is using the remote debugger:
--remote-debugger-port=9000
Using slimerjs for testing scripts with a browser is not advisable since it is based on gecko, which means the script might work on slimerjs and not on phantomjs or viceversa.
take a look at this guide for more info...
https://drupalize.me/blog/201410/using-remote-debugger-casperjs-and-phantomjs

Selenium RC - t.replace is not a function

[edit for godman] I am working on a web based application, written in PHP. I am using Selenium RC to run tests on the webpages produced by this application, through a browser.
I just upgraded to Firefox 14, so I had to upgrade to Selenium RC 2.25.0.
Now I'm seeing this error when running a test with htmlSuite:
Command execution failure. Please search the user group at
https://groups.google.com/forum/#!forum/selenium-users for error
details from the log window. The error message is: t.replace is not a
function
The command executed is:
clickAndWait //a[text()='! selenium test customer']
As you can see, it's not doing anything too tricky - just clicking a link. The test runs fine in the IDE, it's just when run via RC that it's a problem.
Searching in the groups revealed only really old threads dating back to version 1 of selenium.
Any ideas anyone?
[edit] I've been running the test that has these problems several times a day for the last week - and it doesn't seem to fail like this every time. This looks like it's a random problem. Has anyone seen this happen before?
[edit after the bounty got me no answers] Another example of it failing is with:
clickAndWait css=a.edit_company
This same call works fine earlier in the same test, on the same page.
[edit] Now I'm seeing the same error with a completely separate command:
type id=Address1 Address1
Does anyone have any suggestions about this? Any way I can even debug what's going on (I don't see this in the IDE at all)
I am not terribly familiar with clickAndWait. I personally prefer clicking and then doing my own custom waiting.
Try just clicking and add a Thread.Sleep(5000), or something similar, and see if the error is a result of the click or the wait part.
If it is the wait part, then I have a different suggestion than if it is the click part.
I've seen similar issues across various platforms. It has always been somewhat random for me, so I don't use clickandWait. Generally is is much more reliable to do a plain click, and then wait for specific condition. You could do a waitforpageload, but that has also been unreliable for me so I prefer things like waitfortextpresent and waitforelementpresent.
Usually, this kind of error would occur if you are dealing with something that is not a string. Could you just make sure that you are dealing with strings only?
2 possibilities where it is arising from:-
When text() is executed -> it might be dealing with a non-string
a[expression] -> the expression(text() = '! selenium test customer') when evaluated to False/True might be the problem because if a is a Map/array, the corresponding key should be a string and not a bool, probably.
text()='! selenium test customer' -->> is it an assignment operation? if yes, make sure that text() returns a lvalue or a mutable object (based on the language you are using selenium rc with)

Is there a browser-agnostic way to detect client-side script errors with Watin?

We're using WatiN to test our web portals. During the course of an E2E test, we'll occasionally see client-side script errors on the IE status bar. I'd like to chain a handler onto the script error event and record the error for later analysis and bug filing.
Problem is, I don't know that there's a global script error event or how to chain into it. And if there's not a browser-agnostic way to accomplish this, I can create MyIE and MyFF subclasses but then this becomes two browser-specific questions.
In essence, I'm thinking of something like this entirely made-up call:
browser.ScriptEngine.SetCustomErrorHandler(LogScriptingError);
... where LogScriptErrors is my code that does the obvious.
Many of our client-side scripting errors don't necessarily prevent the test from continuing (a pretty UI element didn't animate, for example, but the underlying form is still submittable), so I'd like to log the error and forge ahead in most cases.
You probably looking for this:
window.onerror=function(message, url, line){logError();};
You can add this code to your pages to handle errors in logError(). but this may not work in all browser(works in IE), check this for browser compatibility:
http://www.quirksmode.org/dom/events/error.html
Or you may try this commercial product:
exceptionhub.com/
You could maybe co-opt the ability to inject eval code (described under "Added Eval functionality") to add a script that caught all errors, not just errors from the eval'ed script. I'm not sure if this would work, but it's an area to explore. Another resource might be this blog post, which discusses how to evaluate Javascript in WatiN.