Selenium Webdriver/TestNG/Maven/Xvfb - take screenshot on fail? - maven

wanted to ask you about the best way to take screenshot on fail in such project?
Should I do it in the Selenium code, or in the Maven project via some command or with Xvfb?
Im using Firefox headless via Xvfb.
I have seen a few classes on the internet that take screenshots, but Im missing the big picture here.
How does this class know when to take the screenshot?
How does Jenkins tell the java test code that it has failed, so it will take a picture?
Where in the test code should I reference the take screenshot class?
Should I use a try catch on the whole test?
Isnt there a Jenkins plugin that will automatically save screenshot on fail?

I just found an article that explains a much better way to do it: http://darrellgrainger.blogspot.com/2011/02/generating-screen-capture-on-exception.html
How does it work?
Effectively, you pass in a custom WebDriverEventListener, which has functions that will be called on certain events. One of those events is onException(). So every time an exception is thrown by WebDriver, you can write the code to take a screenshot.
I have seen three different ways to do this:
If you have a static driver, the easiest way is to set up a listener in TestNG (Overridding TestListenerAdapter), and then to take a screenshot in the onTestFailure() method.
My personal method is to use the Selenium Page Object pattern, but modified a bit. I have created an EnhancedWebElement object that wraps and extends a normal WebElement, and has a reference to the driver. Then in each of the methods that WebElement has, I perform the call in a try/catch and in the catch, I then take a screenshot. I'm open to sharing the code, but I'd have to trim away quite a bit to post here, so please tell me if you want to see it.
Alternatively, you can set up a proxy around the WebElement or the Driver itself and have it catch everything. I haven't done this, but I've seen it work on other projects.

just found an article that explains a much better way to do it: http://darrellgrainger.blogspot.com/2011/02/generating-screen-capture-on-exception.html
Blockquote
But this dicision have some problem. it will save screenshoot on any exception even when you try/catch some in your code.
I use methods from that article. But in my testng.xml files i add
`
<listeners>
<listener class-name="MyListener" />
</listeners>
`
And than i create
`
public class MyListener implements ITestListener{
//almost all methods i create blank
//but implement only onTestFailure
//
onTestFailure(){
//here i used methods from article ubove
//
}
}
`
And screenshots done only in case when my #Test fail.

Related

get method hierarchy through static code analyser tools

One of our project, we are trying to find all the leaf method call for a method programmatically. I notice that jdt internal provides to get all the method hierarchy. But those jars not available. Using static code analysis tools, can we get method hierarchy ? or can we get any useful this static code analyser tool for my requirement . Please help me to get this requirement implementation.
Thanks,
Narasaiah
You can try JArchitect (https://www.jarchitect.com).
It could give you all the methods called by another one.

GWT : Automate tests of UIs with Selenium/FluentLenium

I have such a big problem and I really need your help.
Basically, I'm working on a project whose core technology is GWT and I have to make functional tests and the tests of UIs. In fact, I have also to use Cucumber the framework which is BDD-based framework.
Now I come to the main problem : Indeed, at every Maven build, GWT generates automatically the ids of the widgets. Then, Selenium could not find these widgets because of the recent updates/changes of their Ids. Moreover, I can't find some widgets with the methods (findByName/xPath/cssSelector etc.). I'm working now on the FluentLenium which is an overlay of Selenium.. I don't know how to fix this problem because I have no control of how GWT generates the Ids behind ..
Does anynone met the same problem before ?
Thank you a lot.
I've worked with GWT/Selenium/Cucumber. We had a single class file with public static String fields for each ID used in the whole application. These id's were set with ensureDebugId. This same class file is then used in Selenium/Cubumber tests to find the widgets by id. I don't know if this works for you. But in our case the tester was in control of the id's.

Can we add custom action to HtmlLoggerState

I'm using VS2013/CodedUI and my palybacksetting is as follow:
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
I also have a 3rd party tool that I have integrated to my code that does some action that codedui can't...Iw an to be able to log those steps into the ActionLog.html file with where codedui capture the actions and screenshot.
I searched a lot but didn't find anything on how we can achieve this.
thanks in advance for any help
I posted a response over here: Writing Custom HTML Logs
It sounds like there's not a good way to do this. You can get the path to where the html file lives and write a custom logger from there. I'm not sure it'd be safe to try and write to it while your test is executing, but perhaps once your test is complete.

How to trace CakePHP's inner workflow

Short description
I'm getting used to CakePHP right now and am wondering about how to get more debug-information about what is happening inside the framework.
Let me please explain my situation a little more detailed
As you know CakePHP does a lot for you without putting you into the need to write additional code. One example is the handling of models.
I just created a model User and added validation-rules (no other methods). As described in the API methods like save will just work.
After that I created the needed controller and view to add a new user. When I try to add a user from the view I just receive the flash-message The user could not be created. Please, try again. No validation-violations are flashed.
I also did set the debug-level to 2: Configure::write('debug', 2); but do not receive any errors. The error.log inside \tmp\logs is also empty.
I really do want to learn how to solve those issues in the future.
So what else can I do to debug / display inner processes of cake?
Thank you very much for your help!
DebugKit is an official plugin that gives you lots of information on the request, queries and variables produced by Cake:
https://github.com/cakephp/debug_kit
You can also use trace() and other methods in the Debugger to show what is being executed in the background:
http://book.cakephp.org/2.0/en/development/debugging.html
Use a PHP IDE with an integrated debugger. That will allow you to follow execution line by line as it is executed and even inspect variable values as you go. Netbeans is a free one.

How can I avoid mirror effect of image in coverflow

I have downloaded a coverflow sample from the link
http://www.macresearch.org/cocoa-tutorial-image-kit-cover-flow-and-quicklook-doing-things-we-shouldnt-are-too-fun-resist.
I need open flow effect but I dont need miror effect of images.Is it possible to do it.Is there any API available in IKImageFlowView class.
Any help would be appreciated.
There is no API available for IKImageFlowView. It is a private class. That's why the blog post is titled "doing things we shouldn't." If you look at the project in the blog post, you will find a reverse-engineered IKImageFlowView.h. That's as much information as is available. You can use class-dump as noted in the blog post and see if you can find the IKImageFlowViewDelegate protocol if there is one (this class appears to take a delegate). That might allow you to configure it.
Note that Apple may change this class at any time.
You are probably better off using a third-party implementation like MBCoverFlowView or OpenFlow.

Resources