PHPUnit does not report on Not Successful Test - selenium

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.

Related

How to restart test on verify element present

Am new with automation, and currently trying to do something in Selenium IDE but can't seem to find the information on how to do it properly.
So I am running a test on a webpage, clicks and such, and I want if a certain id element is on the page to restart the test, and if not to finish remaining of the code.
Alternatively, this can also be done by verify element not present, but I believe it will slow down the test by searching for something that isn't on the page most of the time.
So the intended steps:
Run Test;
Commands 1, 2, 3... are running
Before Command 19, element id=btnSalir is checked if present on the page
If true, test restarts and goes on the loop until id=btnSalir is not present on the page
If false, test runs remaining code or specific code, whichever is easier.
As alternative steps:
Run Test;
Commands 1, 2, 3... are running
Before Command 19, element id=btnSiguiente is checked if present on the page
If false, test restarts and goes on the loop until id=btnSiguiente is present on the page
If true, test runs remaining code or specific code, whichever is easier.
Also is there a way to reduce the amount of time on these verify element present or not present be reduced?
I tried if, do, repeat if, but can't make it work, maybe someone with some experience can give me some pointers?
Selenium IDE step screenshot
Something like this might help:
if|selenium.isElementPresent("id=btnSalir")
echo|Do some thing
else
echo|Do some other thing
end
The code snippet in the IF statement uses an internal Selenium function to detect if the element is present. The true or false result will cause the correct branch of the if-else-end statement to be executed. Using a construct like this in a test in the IDE will let you do one thing if an element is present and a different thing if it is not present.
Note: This works if you run the test in the Selenium IDE, but will not work if you run the same test in the selenium Side Runner (the "selenium" object is not defined in the Side Runner).

Using 'Run with code coverage' with Intellj idea gets ClassFormatError

Recently I use JMockit and Junit4 for unit tests in intellj idea. When I run my test using the 'Run' button or the 'debug' button, it works fine. When I try to get my code coverage result using the 'Run with coverage' button, it gets ClassFormatError.
java.lang.ClassFormatError at
sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
It happens only when I try to mock a method in the class which I want to test, like
new Expectations(BaseValidator.class) {
{
BaseValidator.isExistAirLineByTwoCode(anyString);
returns(false, true);
}
};
I test another method in class 'BaseValidator' which calls the method 'isExistAirLineByTwoCode'.
I don't know if the cause of this problem is from idea or jmokit, even junit. By the way, I use jacoco for code coverage reports.
How can I fix this problem?
I found a workaround by switching to jacoco runner:
In the menu, click Run --> Edit Configuration --> choose your test under JUNIT category
change coverage runner to Jacoco .

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

Selenium Webdriver Error Unknown strategy class

I've been trying to use Selenium to test my application. I wrote the initial tests using the Selenium IDE but, when I converted the IDE tests to Selenium Webdriver tests I got errors for about half of my code! So I'm going through each of the errors trying to get the code to work.
The error I'm getting in Web Driver is
ERROR: Caught exception [Error: unknown strategy [class] for locator [class=x-tool-close]]
In Selenium IDE it had simply been Command Click and target class=x-tool-close.
Thanks,
It has been awhile since I posted this question so I cannot be sure if I am addressing what the problem was exactly, but with that said the following is what I use for the command I mentioned above.
driver.findElement(By.xpath("//img[contains(#class,'x-tool-close')]")).click();
The structure of this command is very basic. Since the id of my elements are dynamic I search by xpath. Inside the quotation marks we have said xpath. We are searching for an 'img' element whose class attribute contains 'x-tool-close'. Then we are executing the selenium webdriver command click upon that element.

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

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.