Sunday, December 2, 2018

Web Interface Testing technologies / Mocking / Headless Website Testing

  • A headless browser is a web browser without a graphical user interface.Headless browsers provide automated control of a web page in an environment similar to popular web browsers, but are executed via a command-line interface or using network communication. They are particularly useful for testing web pages as they are able to render and understand HTML the same way a browser would, including styling elements such as page layout, color, font selection and execution of JavaScript and AJAX which are usually not available when using other testing methods.

  • Use cases
    Headless browsers are used for:
        Test automation in modern web applications.
        Taking screenshots of web pages.
        Running automated tests for JavaScript libraries.
        Scraping web sites for data.
        Automating interaction of web pages.
    Headless browsers can also be used to:
        Perform DDOS attacks on web sites.
        Increase advertisement impressions.
        Automate web sites in unintended wayse.g. for Credential stuffing.
    https://en.wikipedia.org/wiki/Headless_browser
Tasty mocking framework for unit tests in Java
https://site.mockito.org/
  • Web Interface Testing technologies
Using Mock Objects
 Spring MVC, StrutsTestCaseJSFUnit
 Good for the controller layer
 Doesn't test the HTML screens themselves
– Writing tests to run against a web application
 HTTPUnit, Cactus, JmeterTestMaker,...
– Run tests from within a real web browser
 Selenium

Mockito is a mocking framework that tastes really good. It lets you write beautiful tests with clean & simple API. Mockito doesn't give you hangover because the tests are very readable and they produce clean verification errors
"We decided during the main conference that we should use JUnit 4 and Mockito because we think they are the future of TDD and mocking in Java" - Dan North, the originator of BDD
http://code.google.com/p/mockito/
  • Mocha is a JavaScript test framework for Node.js programs, featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases
https://mochajs.org/


  • Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM

Jasmine is an open source testing framework for JavaScript. It aims to run on any JavaScript-enabled platform, to not intrude on the application nor the IDE, and to have easy-to-read syntax. It is heavily influenced by other unit testing frameworks, such as ScrewUnit, JSSpec, JSpec, and RSpec.
https://jasmine.github.io/


  • Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language. Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, RSpec, jMock, Mockito, Groovy, Scala, Vulcans, and other fascinating life forms.

http://spockframework.org/


  • JMock is a library that supports test-driven development of Java code with mock objects.JMock is a library that supports test-driven development of Java code with mock objects.Mock objects help you design and test the interactions between the objects in your programs

http://jmock.org/


  • EasyMock is an open source testing framework for Java released under the Apache License. The framework allows the creation of test double objects for the purpose of Test-driven Development or Behavior Driven Development.
EasyMock provides Mock Objects for interfaces (and objects through the class extension) by generating them on the fly using Java's proxy mechanism.
EasyMock is a perfect fit for Test-Driven Development.

Why
    Great testing includes isolation
How
Isolation involves Mock Objects
What
EasyMock makes mocking easier
http://easymock.org/


  • JSFUnit is a test framework for JSF applications. It is designed to allow complete integration testing and unit testing of JSF applications using a simplified API. 

http://jsfunit.jboss.org/
  • Headless Website Testing
Run functional tests with frameworks such as Jasmine, QUnit, Mocha, Capybara, WebDriver, and many other.PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
http://phantomjs.org/

  • A headless Internet Explorer browser using the .NET WebBrowser Class with a Javascript API running on the V8 engine.
The API is coded as a port of PhantomJS. Perfect for test automation. If you have used phantom before then you already know how to use TrifleJS.
http://triflejs.org

  • These are browsers that simulate a browser environment. While they are able to support common browser features (HTML parsing, cookies, XHR, some javascript, etc.), they do not render DOM and have limited support for DOM events.

Zombie.js
Insanely fast, headless full-stack testing using Node.js.
http://zombie.js.org/
  • Browserless AJAX Testing with Rhino and Envjs, Part 1
http://loose-bits.com/2011/02/browserless-ajax-testing-with-rhino-and.html
  • A scriptable browser for Web developers.SlimerJS allows you to interact with a web page through an external JS script
https://slimerjs.org/
  • What is Splash?
Splash is a lightweight, scriptable headless browser with an HTTP API. It is used to:
    properly render web pages that use JavaScript
    interact with them
    get detailed information about requests/responses initiated by a web page
    apply Adblock Plus filters
    take screenshots of the crawled websites as they are seen in a browser

https://scrapinghub.com/splash/
  • WireMock is a simulator for HTTP-based APIs. Some might consider it a service virtualization tool or a mock server.

http://wiremock.org/

  • Geb is a browser automation solution.

It brings together the power of WebDriver, the elegance of jQuery content selection, the robustness of Page Object modelling and the expressiveness of the Groovy language.
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.
Geb leverages the WebDriver library for browser automation. This means that Geb works with any browser that WebDriver works with

http://www.gebish.org/


  • Google Test

Googletest - Google Testing and Mocking Framework
Google's C++ test framework
This repository is a merger of the formerly separate GoogleTest and GoogleMock projects

https://github.com/google/googletest

JavaScript Testing

  • How do you test your web app?

  • -Record/Replay
    -Scripting
    -Scripting Page Objects

    Record/Replay
    -Record a test script as you use your application
    -Many tools support this approach
    Selenium IDE
    Commercial tools
    -Pros and cons of Record/Replay
    Intuitive
    Easy to create a test script
    Don’t have to know much about the web application
    Test scripts usually need rework
    Test scripts are fragile
    Test scripts hard to maintain
    Hard to do more complex testing (e.g. data-driven tests)
    Hard to reuse test logic

    Scripting
    -Write a test script using a low-level testing library
    Selenium RC
    HTMLUnit
    -Pros and cons of Scripting
    More powerful tests
    Can do data-driven tests
    Can reuse some test logic
    Higher learning curve
    Need good knowledge of the application
    Test scripts still quite hard to maintain

    Page Objects
    -Create a domain model of your application
    -Hide technical details inside the domain model
    -High level tests written using a different language:
    Programming language (Java,...)
    Scripting language (Groovy, Ruby,...)
    BDD/ATDD framework (easybjbehave,...)
    -Pros and cons of Page Objects
    Much more powerful tests
    Can do data-driven tests
    Easy to reuse test logic
    Tests are easier to maintain
    Tests are understandable by testers
    More up-front thought and design required


    Selenium 2/WebDriver
    Next-Generation version of Selenium
    Build-in support for Page Objects
    One API - Many Drivers
    WebDriver supports several drivers:
    HTMLUnit
    Firefox
    Chrome
    InternetExplorer
    The RemoteWebDriver
    The AndroidDriver
    The iPhoneDriver

    automated-web-testing.pdf




  • build automation


    build scripting
    ant,maven,gradle,gant
    automated code quality
    emma,findbugs
    automated testing
    junit


    The Maven Release Cycle
    -Deploying a release involves many tasks
    -Commit all current changes to version control
    -Upgrade the version number(s) and commit the changes
    -Tag the release version
    -Build and deploy this version
    -Update the version number and commit the changes
    -The Maven Release Plugin automates this process
    Automates the release process
    Updates version numbers
    Commits changes and creates new SCM tags
    Builds, tests and deploys to the Enterprise Repository


    Using the Maven Release Plugin
    mvn release:prepare
    -Audits your code
    Check that there is no uncommitted code
    Check that there are no snapshot dependencies
    Prompts for release tag, branch and new version numbers
    -then does the bookkeeping
    Updates version numbers to release versions
    Creates a new release tag in SCM
    Updates version numbers to next SNAPSHOT versions
    Commit these changes to SCM
    -By default, Maven will prompt you for:
    Release version number
    Release tag
    Next snapshot version number
    -This is not appropriate for automated builds
    mvn release:prepare -B
    -Use batch mode to use sensible default values
    mvn release:perform
    -Do the real work
    Checkout a release version
    Build, test and deploy to the Enterprise repository(archiva,nexus,artifactory etc)
    -Don’t use the maven-release-plugin on your own machine
    -Run it on a build server instea


    Automating the deployment process
    -Don’t rebuild, reuse
    Download application binaries from the Enterprise repository(archiva,nexus,artifactory etc)
    Externalize con?guration as much as possible
    Patch if necessary with target environment con?guration
    Deploy to target environment


    Deployment strategies
    - direct reuse
    - patching


    Deployment strategies - direct reuse
    Reuse from the repository without modi?cation
    Externalized environment-speci?c con?guration
    JNDI
    Local environment-speci?c properties ?les

    Deployment strategies - patching
    Reuse binaries from the repository
    Modify internal con?guration ?les for the target environment
    Can use overlays in Maven



    Automated web deployment with Cargo
    Start, stop and install application servers
    Deploy to different application servers
    Run a stand-alone instance
    Or deploy to an existing server


    Deploying to an embedded Jetty instance
    The simplest way to use Cargo with Maven

    Deploying to a “real” application server
    Deploy to a locally installed instance
    Download and install a server as required
    Deploy to a running server
    Start and stop a server





    Automated web testing
    -Many strategies:
    Run tests before deployment
    Run tests against the deployed application
    -Basic principle - don’t rebuild, deploy
    -Create a special Maven project to run your web tests


    Testing Snapshots or Release Candidates - an approach
    -Use a dedicated release candidate branch
    Changes are merged into the release candidate branches when ready
    Automated tests are (also) run against the release candidate branch
    Releases are run against the release candidate branch
    Updated version numbers need to be merged back to the trunk
    Use multiple repositories on your Enterprise repository(archiva,nexus,artifactory etc)



    automated_deployment.pdf





  • This project demonstrates the basic protractor-cucumber-typescript framework project setup. 

e2e kickstarter test framework which consists of protractor, cucumber frameworks using typescript lang!
https://github.com/igniteram/protractor-cucumber-typescript


  • Delightful JavaScript Testing

Jest is used by Facebook to test all JavaScript code including React applications. One of Jest's philosophies is to provide an integrated "zero-configuration" experience. We observed that when engineers are provided with ready-to-use tools, they end up writing more tests, which in turn results in more stable and healthy code bases.
https://jestjs.io/


  • Front-end

Using jest and enzyme to tests if components are rendered normally.
https://github.com/alpaca0984/QuizMaster

  • spec is a full-featured testing framework that will let you write what Rails considers unit tests, functional tests, and integration tests. All of these exercise Ruby code through various layers of your Rails application. All of these tests simulate requests to your Rails application, but don't actually run the application end-to-end over the network.


cucumber is a browser based integration testing framework, which allows writing automated tests that run against the entire Rails application accessed from within an automated web browser. This allows you to write automated tests about in-browser behavior for JS or CSS. Cucumber provides a unique angle on integration testing that uses plain english specification mapped to code via regular expressions. This allows a more natural "Behavior Driven Development" model - describing what a web application should do, in plain language, from the perspective of the user.

capybara is a particular web driver powering the cucumber integration testing framework, that uses headless webkit. This allows running a headless (without UI) Chrome/Webkit browser for automated testing. This is very useful both in development, but especially on a remote test/continuous integration server.
https://stackoverflow.com/questions/22491145/difference-between-rspec-capybara-and-cucumber


Tests from within a real web browser

  • Cactus is a simple but powerful static website generator using Python and the Django template system. Cactus also makes it easy to develop locally and deploy your site to S3 directly. It works great for company, portfolio, personal, support websites and blogs.
https://github.com/eudicots/Cactus


  • JWebUnit is a Java-based testing framework for web applications. It wraps existing testing frameworks such as HtmlUnit and Selenium with a unified, simple testing interface to allow you to quickly test the correctness of your web applications.

https://jwebunit.github.io/jwebunit/


  • HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.
HtmlUnit is not a generic unit testing framework. It is specifically a way to simulate a browser for testing purposes and is intended to be used within another testing framework such as JUnit or TestNG.
http://htmlunit.sourceforge.net/



  • TestMaker 6 is the easier way to surface performance bottlenecks and functional issues in Web, Rich Internet Applications (RIA, using Ajax, Flex, Flash,) Service Oriented Architecture (SOA,) and Business Process Management (BPM) applications. TestMaker 6 rapidly puts the PushToTest Methodology into your hands for a test tool that installs on your desktop, runs tests in grid and cloud environments, and pinpoints root causes and offers mitigation. Imagine one open source test tool that repurposes a single test script to be a functional test (smoke tests, regression tests,) load and performance test (scalability tests, stress tests,) and production monitors. That test script is a Selenium test, Sahi test, soapUI test suite, and unit test written in Java, Ruby, Python, and PHP. This is TestMaker 6

http://www.pushtotest.com/products.html