What is the difference between Geb and Spock testing frameworks - groovy

I'm new in the area of software developing, and want to extend my knowledge over automation testing. I read a lot for Geb and Spock testing frameworks, but did not come to the conclusion for what purpose are they.
Am I correct:
Geb is for Page Objects (static covering the UI pages selectors, elements, etc.)
Spock is for writing the test order (Cases/Steps for test) (also is able to run API tests as well, mock data, parameterised endpoints, values and etc.)
--> What other differences they have? I already checked both documentations, but cannot understand.
I will appreciate every practical advice or example, differences between both as well, because I covered a lot of things, but there are only theoretical examples, but the main catch I did not get it.
Thank you in advance!

Geb is a browser/web automation solution. You can use it to test the functionality of your web pages. Geb can automatically launch a web page, fill out form fields and click buttons on a web page. From the official website:
"It can be used for scripting, scraping and general automation — or equally as a functional/web/acceptance testing solution via integration with testing frameworks such as Spock, JUnit & TestNG."
The catch for Geb is web automation.
The catch for Spock is that it is testing and specification framework.
Examples
You can Geb to check the following:
When one opens mywebsite.com/login and enters a wrong username or password an error message should be displayed, say in a div.
When one opens mywebsite.com/submitData, fills in item name and price and clicks on the submit button, expect a message to show like "Thank you, the total number of items is now 5"

GEB is build on top of WebDriver library and is compatible all the Browsers and Drivers which work with WebDriver.
Most commonly used way of achieving UI automation is though implementation of Page Object Model design pattern, Geb supports Page Object Model by implementing all the boiler plate code in its 'Page' class. The custom pages in an Automation Framework are required to extend this 'Page' class in order to access ready made functions and closures.
Some Additional points:
It uses jQuery-ish navigator API to identify elements on the page.
There is a ready made 'js' object which lets you execute JavaScripts on your page.
There are closures which let you switch to another Window/iFrame/Alert of your webpage
Simplified handling of Dropdowns,Radio buttons,File Uploads,Checkboxes etc.
Introduces 'Interact' blocks which builds and perform the user actions (by utilizing Action class of Selenium WebDriver API)
geb.config file allows the developer to add support for multiple environments , drivers, Reporting , waiting etc.
Read more about Geb in the The Book of Geb
SPOCK on the other hand is a BDD Testing and Specification Framework inspired from frameworks like JUnit, jMock, RSpec, Groovy, Scala, Vulcans etc.
SPOCK is highly compatible with Geb and provides a 'GebReportingSpec' class which is required to be extended by the test classes in order to establish compatibility with Geb

Related

Best framework to functional test a javascript-injecting bookmarklet

I've developed a bookmarklet that injects some javascript code to a page and I need to write some functional test to test it. Because this is a bookmarklet so I don't have any html files. It will just open another existing website and inject the javascript to that website. I have looked at mocha, selenium-webdriver and Phantomjs, but I just don't which are the best ways to test my bookmarklet.
Have a look at Sakuli. It combines two Open Source test automation tools (Sahi and Sikuli) and lets you test web applications as well as non-web content (e.g. for 100% GUI e2e tests). Both tools can be used in mixed operation.
You can also run Sakuli within Docker containers.

Is it possible to expose hand coded functions as shared steps?

We are looking into coded UI, and since we have C# coding experience we'll be coding up the automated tests ourselves.
I already know that it is possible to have a test case with defined test steps. Each test step is actually a function inside the test method and the description comes from the summary.
This is a great way for the c# coders to expose what they're doing to the non coding testers who will interact with these automated tests using MTM (Microsoft test manager).
However, it would be awesome if the C# coders were able to create generic functions as "Shared Steps" perhaps, and in this way non technical testers were able to assemble new tests in MTM using these building blocks.
Functions such as : Open the settings dialog, Maximize Window, Add an item (with parameters), Close all open tabs, etc.
However these would be coded functions, not from a recording.
The idea would be that once these functions are created and stored in TFS (Again as shared steps), the tester would then be able to use these functions as building blocks for more automated tests.
I also have to stress that these functions will be fully automated, and so new tests assembled in MTM too need to be fully automated without needing to open up Visual Studio.
Is this at all possible?
An approach used by some people is to create a test framework containing many useful functions. The test itself is then written as a data driven Coded UI test, each step being one entry from the data source. (Typically each step might be one line in CSV file.) Some columns of the data source would be commands and others data for those commands.
The commands could be relatively low level such as: find a window, navigate to a page, run an application, find a control in a window, enter text into a field, click a button or a link, verify that a field contains a given string.
Commands could be for higher level activities in your applications, such as: login, fill in a form.
Frameworks can let non coders write tests using terminology they understand. Frameworks are challenging to write.
This isn't really possible in the way you're asking - you will not be able to have your non-technical testers creating automated tests from test manager. A coded UI test will always have to exist as a test in a code file.
All of the details for a test manager test are available through the TFS API, so I suppose it should be possible to create your own layer that could generate coded UI code based on a shared step mapping system, but it would be a fairly major undertaking - its probably easier to have automated tests created by technical people.

Browser Extension the "Injected way" a cross-browser extension that include a JS from a distant server

I've found this nice article about the "injected Way", but the author never finished it :
http://hightechstartups.blogspot.ch/2012/05/different-way-of-developing-browser.html
I would like a bare bone cross browser extension, without any 3rd party extensions or framework (to be as light as possible and not dependant on a 3rd party) that would load Jquery and a JS from a distant server and the ability to load it before or after the page is fully loaded.
I've read a lot of topics about the subject, but since IE10, Chrome 26 and FF20 are out with their new cross-link limitations, i was wondering if somebody had ressources, source code or tutorial about the following requirements :
I need :
Cross browser extension supporting (IE 8+ or 9+ worse case, Chrome
26+, FF20+, Safari)
Ability to inject a single JS hosted on another server. Inserts a script tag that references a javascript file in the head of the HTML
page and then be executed
Not be dependant on a third party extension (greasmonkey) or framework (Kango, Crossrider)
Ability to load before or after the page is fully loaded
This method allows me to customise the browser extension depending on the user's location and it also avoid having updates as the JS is updated on each page refresh.
I'm aware of the downsides, but i would like to achieve this.
I'm aware of cross browser framework like Kango or crossrider, but both don't fit me needs.
The closest example i could find is this How can I run a <script> tag that I just inserted dynamically from a BHO
but it only covers IE and as i got very little Csharp experience, i would like to see a full example to understand it properly and learn from example.
I would LOVE to have a few examples, even if it's not cross-browser (IE being the worst part for me).
Thanks a lot for your support !
Update1:
About Kango and Crossrider, Kango is 2000$ if you want to use IE and for Crossrider you're required to be distributed and monetized by them.
I've managed to code for IE and Chrome, but i was looking for an "elegant" way and figured it was the best place to ask given the level of knowledge of people on this site.
For the installer i currently use NSIS, but i'll test Wix too.
Finally i guess the only way for me would be to learn C++ and .net to get it to work with IE, but if anyone could provide more source code it would be great to test speed and compatibility and discuss here what's the best solution.
Why do Kango or Crossrider not fit your needs? Both frameworks allow you to manipulate the page's DOM (which is what you want):
Kango: Adding content script
Crossrider: documentation, example code
If you want to code your own solution, take a look at the relevant documentation:
Content scripts (Chrome)
The Page mod Jetpack API (Firefox)
Injected scrips (Safari)
Injected scripts (Opera)
Internet Explorer does not natively support extensions. It took me about 80 hours to create a stable and reliable IE extension which supports cross-site AJAX, a (preference) storage method and injection of scripts as early as possible in any frames based on its URL. I developed and tested the extension with Visual Express 2010 on Windows XP and Windows 7, for IE 8-10 (the extension might work on IE6/7, but I decided to not support these ancient and rarely used browsers).
First, I wrote an extension in C# based on LiveReloadIEExtension (a sample IE extension, which in turn is based on this Stack Overflow answer - see also this blog post). It was functional, but it required .NET 4, lacked support of frames, and it's relatively slow.
So, I decided to write an IE extension from scratch in C++. A good starting point is available at http://www.wischik.com/lu/programmer/bho.html: Sample code for C++ BHO, which changes the document's background based on key/mouse events. I've also learned a lot by looking at other code samples on CodeProject, topics on the MSDN forums, questions and answers on Stack Overflow, lots of other blogs, and the MSDN documentation:
DWebBrowserEvents2 interface lists several events which you use to find an appropriate injection point.
Scripting Object Interfaces (MSHTML) lists even more interfaces. You'll be mainly interested in the iHTMLDocument, iHTMLDocument2, ... interfaces.
After creating the IE extension, you want to deploy it of course. I used Wix toolset to create a MSI.

HTML5 canvas and BDD - Cucumber

I was learning about Behavior driven development (BDD) recently, i see that its good for CRUD web application.
Is BDD tools such as Cucumber suitable for games, specifically are they good for HTML5 Canvas games?
Is there any other BDD tools for HTML5 canvas games? Or Is BDD only for CRUD applications?
I've just recently been experimenting with BDD and Games Development. But I'm building on the .NET & XNA Frameworks with C#. I'm using Visual Studio as my IDE and testing with SpecFlow and NUnit.
SpecFlow is the BDD/Gherkin tool - and as a group we've been talking about the game and fleshing out some requirements and documenting them in Gherkin... and going from there. The key is designing the game to be testable.
We've abstracted the game engine away from main "game loop" implementation that XNA requires so we are able to load it up and inject all of the dependencies it requires. We then run the tests on the engine and make asserts on the code afterwards to make sure that it is behaving correctly.
We decided early on that Graphics/Drawing/Sound/etc were out of scope of the testing... if they were broken in the end product, it would be very obvious. The test suite we've managed to build up just gives us the confidence that the mechanics of the game itself are working as intended (i.e. is game object A in the right location? does game object B die when hit with projectile C? etc. etc.).
So far it has been quite a good experience.
The question is: can you think of ways to interact with the canvas-based game in JavaScript?
Practically, could you open the JS console and interact with the game from there? Can you fire clicks at the right coordinates, can you press keys and most importantly, can you make assertions on what's being output by the game?
If the answer is yes, then you are able to automate the game in JavaScript and either Cucumber or Cucumber.js can definitely be used on top of that.
If the answer is no and you can't figure out a way to automate the canvas content in a similar fashion than what described above, then I'm afraid no automation tool could do the job.
To answer your second question: BDD has absolutely nothing to do with "CRUD" applications. It's about describing behaviours and automating examples that illustrate those behaviours. You can therefore take a BDD approach on virtually any types of application.
Shouldn't you find a way to automate your application, you could still consider writing scenarios to document the (expected) behaviour of your app. The automation phase is not mandatory, contrary to common beliefs :)

Rails Integration Testing

I'm looking to set up a bunch of integration tests for an Rails 3 app that is already built.
The app is built with Rails 3 and Ruby 1.9.2. I've seen recommendations for Capybara, Cucumber and RSpec 2 but I'm not sure what the advantages of each are.
I've also noticed that they seem to be closely tied together. The post I've seen always seem to talk about using Capybara with Cucumber, or using Rspec with Cucumber.
What are the advantages/disadvantages for each of them? Are there certain combinations that work best together?
All these test tools fall in different parts of the testing environment.
If you want to set up integration tests, then you should use Cucumber because it has no real alternative. Cucumber is designed to easy Behaviour Driven Development but even if you don't BDD it is perfect for integration testing.
Capybara mission statement is "webrat alternative which aims to support all browser simulators". So to simulate the browser part (http request, DOM manipulation, etc) you have two alternatives Webrat or Capybara. Cucumber integrates fine with both of them. In fact it detects which one you have installed in your system and by default uses it.
On the other side is Rspec. Rspec is not a tool for Integration Testing but for Unit Testing (with a BDD approach). In http://www.pragprog.com/titles/achbd/the-rspec-book it is explained very clearly. Cucumber is in an outer circle of application behaviour and rspec is in an inner circle of class behaviour. The alternative to rspec is classic Test::Unit classes.
For more information see:
Cucumber
Capybara
Webrat
RSpec
Test::Unit
In summary, use all three.
Use RSpec...
...for testing methods in your models, controllers, and helpers in isolation.
Also known as Unit testing.
Use Cucumber...
...for testing high level features of your application.
Also known as integration testing. Verifies that all the pieces work together.
Good for testing from a user's perspective.
Use Capybara with Cucumber...
...for navigating your app like a user would through the browser.
...for testing your views contain the content that a user would expect to see.

Resources