Can I use captureScreenshotOnFailure to capture an error not only the failure in selenium RC? - selenium

I'm trying to capture the screen whenever something goes wrong, either an error or failure

You can use selenium.captureScreenshot() create a util method which you can call whenever you want to capture the screen shot. However if you are using Testng then you can refer http://satishjohn.wordpress.com/2012/06/04/selenium-testng-error-screenshot-listene/ but this is for failedtest passedtest skipped test. however you can put the capturescreen shot as a helper method in you utilities and call it under the testng method.

Related

Selenium - watch for an error condition AND run 'happy path' test code

My app displays an error dialog whenever a JavaScript error occurs. This is always a bad sign, so I want to set up my tests so that, if the error dialog appears, it causes the test to fail there and then.
So I'd like to do something like (very much pseudocode!);
// start a new 'guard' thread;
start {
found = this.driver.wait(untilVisible(By.css('.myErrorDialog')), VERY_LONG_TIMEOUT);
if (found) {
// the error dialog appeared! That's bad!
throw();
}
}
// now run the test
login();
clickButton();
testBannerContains();
But I'm having trouble and I think it has to do with the way Selenium schedules actions.
What I've found is that for a single driver, I can only schedule one thing at a time, so the guard I set up early in the test blocks the body of the test from starting.
Is there a better way to handle conditions like 'this should never happen', or a way to create two independent threads in the same test?
So the problem with the code you have is that it immediately runs it and waits for a VERY_LONG_TIMEOUT amount of time for that error dialog to appear. Since it never does, it continues to wait. You have already discovered that is not what you want... ;)
I haven't done anything like this but I think you want a JS event handler that watches for the event that is triggered when the error dialog appears. See the link below for some guidance there.
Can my WebDriver script catch a event from the webpage?
One option would be to watch for that event to fire and then store true (or whatever) in some JS variable. Before leaving a page, check to see if the variable is set to true and if so, fail the test. You can set and get JS variables using JavascriptExecutor. Some google searches should get you all you need to use it.

Mouse over action in Protractor

I am new to Protractor. Can anyone tell me how can we use Actions like mouse over,drag and drop(like Actions in Selenium) in Protractor. I need just a syntax or a code snippet.
It is actually there, inside the Protractor API documentation: .actions():
browser.actions().
mouseDown(element1).
mouseMove(element2).
mouseUp().
perform();
A common problem is to forget calling perform() at the end which may results into it doing nothing. We actually had a weird test that had an action chain without the perform() and, because of the incorrect expectation the test just passed. You can catch these types of problems statically now, with eslint-plugin-protractor (shameless self-promotion).

Selenium: Check i the testcase pass or fail

Guys First of all I am totally new for Selenium.
I am having a automation project. In my project, I am creating a screenshot function to take screenshots of my event which I have created for my testcases. Now if my test cases passes then all screenshot should move to Pass folder, else fail folder.
I would like to know how to detect that my test case pass?
I know Nunit detects but I wanted to program it so that I cam place my screenshot as well as log file to pass or fail folder.
Program in C#
Selenium
Nunit to run my test case.
I think you meant was this. But there is work around for this. You need to add your code accordingly.
if (TestContext.CurrentContext.Result.Outcome.Equals(ResultState.Failure))
{
IntegrationTest.WriteInLog("FAILS");
}
else if (TestContext.CurrentContext.Result.Outcome.Equals(ResultState.Success))
{
IntegrationTest.WriteInLog("SUCESS");
}
Check status property and compare it with TestStatus enum at teardown method.
NUnit2:
TestContext.CurrentContext.Result.Status
NUnit3:
TestContext.CurrentContext.Result.Outcome.Status

PHPUnit does not report on Not Successful Test

I've install PHPUnit3.6.2 and tried to run simple test.
If test Successful, there are no problems: phpunit reporting that test is OK.
But if there any error in test, PHPUnit reporting NOTHING! No failure and error text, no line in test.php, just empty line.
If it can helps: in browser code ends with getLocation() method. But I didnt use such method in my test.
why is this happening?
Also I should add: if in test use some element, wich not present on web page (for example button with wrong x-path). And there is action with this button in test:
$this->clickAt("wrong x-path");
phpunit doesn't show error report too. It continues to run. Looks like it found this button and clicked it. But there is NO such button on page.
No errors, no failures, test doesn't stop...
You are alking about Selenium testing. getLocation() is called by PHPUnit when formatting the failure report (to display the URL on which the failure occurred). You should try some simple (non-Selenium) PHPUnit tests to see if failure/error reporting works there, so you can narrow it down to Selenium or PHPUnit itself.

Extending Selenium: How to call commands?

I read about user extensions and extending selenium but am wondering how to call a command from within a custom command I'm creating.
I added a file similar to the following to Selenium core extensions (user-extensions.js) in Selenium IDE Options.
// selenium-action-example.js
Selenium.prototype.doExample = function() {
this.doOpen("/"); // doesn't waitForPageToLoad like the command does
// These two commands are equivalent to the clickAndWait command. NOT!
// For proof, see the filterForRemoteControl function:
// http://code.google.com/p/selenium/source/browse/trunk/ide/src/extension/content/formats/formatCommandOnlyAdapter.js?r=8284#68
this.doClick("css=a#example");
this.doWaitForPageToLoad(); // doesn't wait at all
this.doClick("link=Example");
this.doWaitForElementPresent("example"); // error! undefined function
this.doClick("example");
};
In other words, how can I wait for things between clicks within a custom action?
Your command
this.doWaitForPageToLoad(); // doesn't wait at all
Doesn't wait as you have not specified wait time in brackets. You should write it as
this.doWaitForPageToLoad(30000); // time in milliseconds
Tour another Command
this.doWaitForElementPresent("example"); // error! undefined function
as no function is there in Selenium. whenever it waits for an element it checks that element is present or not so you should wait for time until it is visible/present.
Using For loop and ispresent commands you can do it.
Regards
Waiting for an page load does not to work in current versions of Selenium. As far as I can see, this is because the doWaitForPageToLoad defers the waiting until the end of the current Selenium IDE command, i.e. waiting for a page load stops the test execution until the page has loaded, but not the execution of the actual javascript function that this was executed in.
You will have to split your function in two at this point.