Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Key Points


References

Reference_description_with_linked_URLs_____________________________________Notes_________________________________________________________________


https://www.softwaretestinghelp.com/open-source-testing-tools/

https://drive.google.com/open?id=1N9QHJbbfaVSpQVL9XG2L9p8KOLOyT5UD

20 best open-source test tools, frameworks

https://dzone.com/articles/10-best-open-source-test-automation-frameworks-for

https://drive.google.com/open?id=1E8KkVLAE2jWddWVyBHuT_v0LmvkGKb2E

10 best open-source test frameworks

https://techbeacon.com/app-dev-testing/top-11-open-source-testing-automation-
frameworks-how-choose

https://drive.google.com/open?id=16bbFYqPKC_hOBVYctLHzo0ZVkbAgn-Lr

11 open-source test automation frameworks
https://www.softwaretestinghelp.com/open-source-testing-tools/Open source testing frameworks


https://curl.haxx.se/docs/manual.htmlCurl Manual
https://flaviocopes.com/http-curl/Curl tutorial - flavio copes


https://www.guru99.com/top-6-api-testing-tool.htmlAPI Testing Tools list

Selenium Web Driver

Spock

Geb

Cucumber



Openapi

Swagger
https://www.getpostman.com/Postman
https://gist.github.com/corbanb/db03150abbe899285d6a86cc480f674dPostman tips
https://www.getpostman.com/how-api-collaboration-worksHow to use Postman
https://www.getpostman.com/pricingbase = free, normal = $8 / user / mo
https://learning.getpostman.com/Learn Postman

https://support.postman.com/hc/en-us/articles/360008893713-
How-do-I-configure-Postman-to-work-through-a-proxy-

postman-proxy-config-2020-support.postman-How do I configure
Postman to work through a proxy.pdf

Setup Postman through a proxy server to Internet ( or use OpenVPN)
https://github.com/postmanlabs/postman-app-support/issues/2646

Postman error: need to enable javascript

>> real issue - hit an invalid web url w bad config value for url



https://github.com/MicroShed/microshed-testingMicroshed - test Java container apps


https://robotframework.org/Robot Test Framework - Https tests eg curl 
https://chercher.tech/robot-framework/manual-testing-robot-frameworkManual tests using Robot in other frameworks
https://medium.com/arcadia-software-development/automate-test-api-
with-robot-framework-3035af1c9e22
Robot Test Https article - medium
https://chercher.tech/robot-framework/automation-of-rest-api-robot-frameworkRobot REST API automation framework
https://www.udemy.com/course/robot-framework-api-testing/


https://behave.readthedocs.io/en/latest/Behave BDD open source

https://www.guru99.com/bdd-testing-rest-api-behave.html

api-behave-bdd-guru99.com-Behavior-Driven DevelopmentBDD Testing
a REST API With Behave.pdf

Behave tutorial
https://jbehave.org/JBehave  - Java BDD framework - eos





Key Concepts


More test tools


testing tools

https://github.com/TestLinkOpenSourceTRMS/testlink-code
https://www.google.com/search?client=firefox-b-1-d&q=testlink+tutorial
https://www.guru99.com/testlink-tutorial-complete-guide.html

...

https://robotframework.org/
https://www.tutorialspoint.com/robot_framework/index.htm
https://github.com/robotframework/robotframework


Older tools that may not work

Canoo WebTest

https://github.com/canoo/webtest

...

canoo-webtest-review-2011-wo.com-Canoo webtest-vs-selenium-webtest-wins-13-5.pdf



curl


https://flaviocopes.com/http-curl/

...

curl-flaviocopes.com-The curl guide to HTTP requests.pdf

Swagger - OpenAPI




Postman - API Test Tool


Free Postman account


jm9@gmail


https://web.postman.co/workspaces?type=personal

...

api requests in a collection can be created, copied, moved, deleted

Create a public login request

/login in a collection in the workspace

create an API request test

url

{{authenticationBaseUrl}}/login

...

__cfduid=d788c04eea1b79504ecad092f49a88c4f1565225862; path=/; domain=.dmx.io; HttpOnly; Expires=Fri, 07 Aug 2020 00:57:42 GMT;


create test scripts

before and after request

after request script - sets environment variables from returned json jwt

const jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("DMXToken", jsonData.token);
postman.setEnvironmentVariable("userId", jsonData.user._id);
const authDataUserEmail = jsonData.user.email;
postman.setEnvironmentVariable("userEmail", authDataUserEmail);
const authDataUserEmailDomain = authDataUserEmail.split("@")[1];
postman.setEnvironmentVariable("userEmailDomain", authDataUserEmailDomain);


Passing a CSV file on POST request



Image Added


How to Use Postman

https://www.getpostman.com/how-api-collaboration-works

...

need for collaboration has grown and changed as APIs have become more integrated with services—and even become products themselves. Now, API consumers aren't just developers. They are customer support, go-to-market, and developer relations teams who need to stay up-to-date on the latest changes.

API-First Development

An API-first approach starts with API design and development before writing a single line of code. This allows you to:

  • Save time and effort by gathering feedback and make changes early,

  • Ensure compatibility with all devices, platforms, and operating systems.

Code and API Repositories

Just like code, APIs need a single, dedicated space that:

  • Allows both producers and consumers to find, build, and learn about APIs,

  • Integrates with source code repositories to keep the API and software development lifecycles in sync.

Producers and Consumers

API development requires close collaboration between consumers and producers.

  • Consumers need stay up-to-date on the latest changes to how the API works,

  • Producers need feedback from consumers to ensure they're building the right thing.

Postman makes it easy to create this feedback cycle by providing a single platform where producers and consumers can work and communicate together.jbeh

Integrations

Building APIs is complex and requires a number of different tools. Postman helps the tools you use work better together through:

  • Built-in integrations and the Postman API.

  • Easy integrations with third-party tools like GitHub, Datadog, and many more.

What is a Workspace?

A workspace is a shared context for building and consuming APIs. Postman workspaces allow real-time collaboration within and between teams with built-in version control.

Create a Shared Context

Workspaces provide a shared context for your APIs, helping your team get up to speed and stay up to date. With workspaces, you can:

  • Mirror your team's workflow with workspaces dedicated to a particular project or to specific functions like technical writing or testing.

  • Join multiple workspaces and share work across all of them.

Invite Users and Share Work

Invite as many users as you want to collaborate in workspaces.

  • Maintain granular access control with roles and permissions.

  • Collaborate on collections in real time to keep teams on the same page.

Create a Feedback Loop

Use comments to give and receive feedback on requests, APIs, and collections, creating faster feedback cycles that reduce development time.

Work in Parallel with Version Control

Workspaces support core version control concepts like forking, merging, and conflict resolution, allowing teams to:

  • Easily resolve conflicts.

  • Collaborate on multiple forks simultaneously.

  • Seamlessly merge changes.

What is a Collection?

Collections are executable API descriptions. They are groups of related requests and are the primary building block for all of Postman's features, allowing you to build mock servers, generate documentation, create monitors and build test suites.

Collections: Executable API Descriptions

While static API descriptions in the OpenAPI, RAML, or GraphQL formats describe how your API is supposed to behave, collections show how it actually behaves.

To keep your collections and schemas in sync, write and edit the schema directly in Postman or import a schema and convert it into a collection.

Postman Runtime

The open source Postman Runtime executes all API requests, ensuring consistent request execution across Postman's products, including:

Postman Collection SDK

The Postman Collection SDK is an open-source project that defines the collection format. It provides:

  • Helpful tools for generating and parsing collections,

  • Visibility into the collection format, defined by a JSON-based schema

What is an API in Postman?

An API in Postman defines metadata like name, descriptions, and versions, along with elements like schema, documentation, environments, and test suites.

Organize Your API Workflow

Manage your workflow in four stages.

  • Define APIs in formats like OpenAPI, GraphQL, and RAML.

  • Develop your API by adding mock servers, documentation, and environments to specific API versions.

  • Test your API by writing integration and contract tests.

  • Observe your API by monitoring it for performance and response time.

Track Development with Version Tags

Easily maintain multiple versions of an API and its elements at the same time.

  • Define multiple versions of an API.

  • Keep track of you development process.

  • Organize your work with your preferred naming convention.

Increase Flexibility with Schemas

Write, edit, and import schemas in Postman.

  • Create APIs with schema formats including OpenAPI, GraphQL, and RAML.

  • Easily generate collections from your API schema.

  • Develop in parallel by sharing schemas with development and testing teams early on.

Connect It All on One Platform

Organize and manage every aspect of your API development workflow in one place.

  • Maintain a sharable source of truth between your team and with other teams.

  • Maintain multiple versions of your API and API elements in one place.

  • Automatic syncing ensures all linked elements are up-to-date and in sync.


Postman Errors at Runtime


Many runtime errors can be analyzed in the Postman client by:

  1. validating the url for the host app is correct
  2. ensuring the request url is correct with the substituted values for any values
  3. viewing Postman console for the request / response data actually sent and received
  4. viewing Postman logs for requests/ responses
  5. checking headers, authentication methods on the test case
  6. checking pre-request scripts
  7. checking the test scripts for potential errors based on missing data in the response ( try removing the post tests temporarily and re-run the test )


Resolving an issue in the Deprecated Chrome Postman Plugin for Javascript support in web page accessed

https://github.com/postmanlabs/postman-app-support/issues/2646

Problem

Sending a request to some pages, keep getting the error 'Javascript is disabled on your browser. Please enable Javascript and refresh this page'. The page works on the browser but on Postman it comes up with that error. Initially thought it was the page so tried another and still keep getting the error

Solution

  1. Postman Version: 4.9.3
  2. App (Chrome app or Mac app): Mac app
  3. OS details: 10.12.2
  4. Is the Interceptor on and enabled in the app: No
  5. Did you encounter this recently, or has this bug always been there: N/A
  6. Expected behaviour: N/A
  7. Console logs (http://blog.getpostman.com/2014/01/27/enabling-chrome-developer-tools-inside-postman/ for the Chrome App, View->Toggle Dev Tools for the Mac app): N/A
  8. Screenshots (if applicable) N/A

For some reason, I need run javascript and submit forms in Preview. I know postman doesn't support it for security (CSP). So I inspected postman's source code via DevTools, and finally I found

131078                 { className: 'response-body-iframe-viewer' },
131079                 _react2.default.createElement('iframe', {
131080                   className: 'response-body-viewer-preview',
131081                   sandbox: '' // https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe#attr-sandbox
131082                   , src: this.props.src
131083                 })

in /Applicatoins/Postman.app/Contents/Resources/app.js

Then I modify line 131081 to
sandbox: 'allow-forms allow-scripts'

relaunch postman, it works!

I think it's may not safe when using postman under sandbox: 'allow-forms allow-scripts' all the time. So maybe we could add a button to postman's preferences settings, then we can enable/disable it as needed.


Automating API tests in Postman

https://www.postman.com/use-cases/api-testing-automation



Robot Framework for Test Automation

is Robotframework's HttpLibrary (Requests)

...

Robot Framework is actively supported, with many industry-leading companies using it in their software development.

Robot Framework is open and extensible and can be integrated with virtually any other tool to create powerful and flexible automation solutions. Being open source also means that Robot Framework is free to use without licensing costs.


Robot Framework has easy syntax, utilizing human-readable keywords. Its capabilities can be extended by libraries implemented with Python or Java. The framework has a rich ecosystem around it, consisting of libraries and tools that are developed as separate projects.

...

Code Block
languagepy
titleSample Test Case
collapsetrue
*** Settings ***
Documentation     A test suite with a single test for valid login.
...
...               This test has a workflow that is created using keywords in
...               the imported resource file.
Resource          resource.txt

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    Input Username    demo
    Input Password    mode
    Submit Credentials
    Welcome Page Should Be Open
    [Teardown]    Close Browser


Run Reports


Define Keywords for Test Case ( variable ) 

Code Block
languagepy
titleDefine Keywords for Tests
collapsetrue
*** Settings ***
Suite Setup       Open Browser To Login Page
Suite Teardown    Close Browser
Test Setup        Go To Login Page
Test Template     Login With Invalid Credentials Should Fail
Resource          resource.txt

*** Test Cases ***               User Name        Password
Invalid Username                 invalid          ${VALID PASSWORD}
Invalid Password                 ${VALID USER}    invalid
Invalid Username And Password    invalid          whatever
Empty Username                   ${EMPTY}         ${VALID PASSWORD}
Empty Password                   ${VALID USER}    ${EMPTY}
Empty Username And Password      ${EMPTY}         ${EMPTY}

*** Keywords ***
Login With Invalid Credentials Should Fail
    [Arguments]    ${username}    ${password}
    Input Username    ${username}
    Input Password    ${password}
    Submit Credentials
    Login Should Have Failed

Login Should Have Failed
    Location Should Be    ${ERROR URL}
    Title Should Be    Error Page
                    


Set Values for Keywords in Test


Code Block
languagepy
titleSet Values for Test Keywords
collapsetrue
*** Settings ***
Library           SeleniumLibrary

*** Variables ***
${SERVER}         localhost:7272
${BROWSER}        Firefox
${DELAY}          0
${VALID USER}     demo
${VALID PASSWORD}    mode
${LOGIN URL}      http://${SERVER}/
${WELCOME URL}    http://${SERVER}/welcome.html
${ERROR URL}      http://${SERVER}/error.html

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open

Login Page Should Be Open
    Title Should Be    Login Page

Go To Login Page
    Go To    ${LOGIN URL}
    Login Page Should Be Open

Input Username
    [Arguments]    ${username}
    Input Text    username_field    ${username}

Input Password
    [Arguments]    ${password}
    Input Text    password_field    ${password}

Submit Credentials
    Click Button    login_button

Welcome Page Should Be Open
    Location Should Be    ${WELCOME URL}
    Title Should Be    Welcome Page

...

Libraries contain framework functions

Libraries provide the actual automation and testing capabilities to Robot Framework by providing keywords. Several standard libraries are bundled in with the framework, and galore of separately developed external libraries that can be installed based on your needs. Creating your own libraries is a breeze.


Standard


Builtin
Provides a set of often needed generic keywords. Always automatically available without imports.

...

XML
Library for generating, modifying and verifying XML files.


Tools 


Built in Tools 

...

Other RPA Automation Tools for Robot


Learn Postman

https://learning.getpostman.com/



Microshed - test framework for Java microservices in containers

https://github.com/MicroShed/microshed-testing

...

Add Add microshed-testing-testcontainers and junit-jupiter as test-scoped dependencies to a Maven project

Run with Maven:

./gradlew publishToMavenLocal
cd sample-apps/maven-app
mvn clean install

Run with Gradle:

./gradlew :microshed-testing-jaxrs-json:test

...

Runs with JEE containers:  TomEE, OpenLiberty etc


Sample Java-RS application

Code Block
languagejava
titleJava RS example for Person object
linenumberstrue
collapsetrue
@Path("/people")
@ApplicationScoped
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class PersonService {

    private final PersonRepo personRepo = // ...

    @GET
    public Collection<Person> getAllPeople() {
        return personRepo.values();
    }

    @GET
    @Path("/{personId}")
    public Person getPerson(@PathParam("personId") long id) {
        Person foundPerson = personRepo.get(id);
        if (foundPerson == null)
            throw new NotFoundException("Person with id " + id + " not found.");
        return foundPerson;
    }
    
    // ...
}


Microshed integration tests for Java - RS example


Code Block
languagejava
titleMicroshed test script
linenumberstrue
collapsetrue
@MicroShedTest
public class BasicJAXRSServiceTest {

    // This will search for a Dockerfile in the repository and start up the application
    // in a Docker container, and wait for it to be ready before starting the tests.
    @Container
    public static MicroProfileApplication app = new MicroProfileApplication()
                    .withAppContextRoot("/myservice");

    // This injects a REST _Client_ proxy of the PersonService shown above
    // This allows us to easily invoke HTTP requests on the running application container
    @Inject
    public static PersonService personSvc;

    @Test
    public void testGetPerson() {
        // This invokes an HTTP POST request to the running container, which triggers
        // the PersonService#createPerson endpoint and returns the generated ID
        Long bobId = personSvc.createPerson("Bob", 24);
        
        // Using the generated ID, invoke an HTTP GET request to read the record we just created
        // The JSON response will be automatically converted to a 'Person' object using JSON-B 
        Person bob = personSvc.getPerson(bobId);
        
        assertEquals("Bob", bob.name);
        assertEquals(24, bob.age);
        assertNotNull(bob.id);
    }
    
    @Test
    public void testGetUnknownPerson() {
        // This invokes an HTTP GET request to get a person with ID -1, which does not exist
        // asserts that the application container returns an HTTP 404 (not found) exception
        assertThrows(NotFoundException.class, () -> personSvc.getPerson(-1L));
    }

    // ...
}



Potential Value Opportunities



Potential Challenges



Candidate Solutions



Webinars voice to Google docs text 


speech to text recognition 

...

https://www.howtogeek.com/364369/how-to-record-your-pc%E2%80%99s-audio-with-virtual-audio-cable/




API Test Tools List


An API or Application programming interface is a collection of software functions and procedures through which other software applications can be accessed or executed. In API Testing you use software to send calls to the API, get output and log the system's response. For Agile development, Api Testing becomes important as shorter development cycles put more pressure on automated testing.

...

Download link: https://smartbear.com/product/ready-api/soapui/overview/



Behave - BDD test framework using Python

https://behave.readthedocs.io/en/latest/

...

Now make a directory called "features/". In that directory create a file called "example.feature" containing:

# -- FILE: features/example.feature
Feature: Showing off behave

  Scenario: Run a simple test
    Given we have behave installed
     When we implement 5 tests
     Then behave will test them for us!

Make a new directory called "features/steps/". In that directory create a file called "example_steps.py" containing:

# -- FILE: features/steps/example_steps.py
from behave import given, when, then, step

@given('we have behave installed')
def step_impl(context):
    pass

@when('we implement {number:d} tests')
def step_impl(context, number):  # -- NOTE: number is converted into integer
    assert number > 1 or number == 0
    context.tests_count = number

@then('behave will test them for us!')
def step_impl(context):
    assert context.failed is False
    assert context.tests_count >= 0

Run behave:

$ behave
Feature: Showing off behave # features/example.feature:2

  Scenario: Run a simple test          # features/example.feature:4
    Given we have behave installed     # features/steps/example_steps.py:4
    When we implement 5 tests          # features/steps/example_steps.py:8
    Then behave will test them for us! # features/steps/example_steps.py:13

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined

...




JBehave  - Java BDD framework - eos

https://jbehave.org/


Create a BDD story with example scenarios 

A story is a collection of scenarios, each detailing different examples of the behaviour of a given increment of functionality of the system.

trader_is_alerted_of_status.story.

Given a stock of symbol STK1 and a threshold of 10.0
When the stock is traded at 5.0
Then the alert status should be OFF

...

Then the alert status should be ON

Map scenarios to Java methods with annotations

https://jbehave.org/reference/stable/developing-stories.html#writing

...

public class TraderSteps { // look, Ma, I'm a POJO!!
  
    private Stock stock;
 
    @Given("a stock of symbol $symbol and a threshold of $threshold")
    public void aStock(String symbol, double threshold) {
        stock = new Stock(symbol, threshold);
    }
 
    @When("the stock is traded at $price")
    public void theStockIsTradedAt(double price) {
        stock.tradeAt(price);
    }
 
    @Then("the alert status should be $status")
    public void theAlertStatusShouldBe(String status) {
        ensureThat(stock.getStatus().name(), equalTo(status));
    }
 
}




Configure Stories with data scenarios 

At the heart of the JBehave running of stories lies the Embedder, which provides an entry point to all of JBehave's functionality that is embeddable into other launchers, such as IDEs or CLIs. JBehave complements the Embedder with an Embeddable which represents a runnable facade to the Embedder.

JBehave allows many different ways to configure Embeddable Java classes that allow the parsing and running of textual stories.

JBehave provides two main Embeddable implementations:

JUnit-enabled Embeddables

JUnit is supported out-of-the-box via several Embeddables implementations:

...

Code Block
languagejava
titleTraderStories
public class TraderStories extends JUnitStories {
 
    private final CrossReference xref = new CrossReference();
 
    public TraderStories() {
        configuredEmbedder().embedderControls().doGenerateViewAfterStories(true).doIgnoreFailureInStories(false)
                .doIgnoreFailureInView(true).doVerboseFailures(true).useThreads(2).useStoryTimeoutInSecs(60);
        //configuredEmbedder().useEmbedderControls(new PropertyBasedEmbedderControls());
    }
 
    @Override
    public Configuration configuration() {
        Class<? extends Embeddable> embeddableClass = this.getClass();
        Properties viewResources = new Properties();
        viewResources.put("decorateNonHtml", "true");
        viewResources.put("reports", "ftl/jbehave-reports-with-totals.ftl");
        // Start from default ParameterConverters instance
        ParameterConverters parameterConverters = new ParameterConverters();
        // factory to allow parameter conversion and loading from external resources (used by StoryParser too)
        ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters);
        // add custom converters
        parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
                new ExamplesTableConverter(examplesTableFactory));
        return new MostUsefulConfiguration()
            .useStoryLoader(new LoadFromClasspath(embeddableClass))
            .useStoryParser(new RegexStoryParser(examplesTableFactory)) 
            .useStoryReporterBuilder(new StoryReporterBuilder()
                .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
                .withDefaultFormats()
                .withViewResources(viewResources)
                .withFormats(CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE)
                .withFailureTrace(true)
                .withFailureTraceCompression(true)                
                .withCrossReference(xref)) 
            .useParameterConverters(parameterConverters)                     
            // use '%' instead of '$' to identify parameters
            .useStepPatternParser(new RegexPrefixCapturingPatternParser(
                            "%")) 
            .useStepMonitor(xref.getStepMonitor());                               
    }
 
    @Override
    public InjectableStepsFactory stepsFactory() {
        return new InstanceStepsFactory(configuration(), new TraderSteps(new TradingService()), new AndSteps(), new MetaParametrisationSteps(),
                new CalendarSteps(), new PriorityMatchingSteps(), new PendingSteps(), new SandpitSteps(),
                new SearchSteps(), new BeforeAfterSteps(), new CompositeSteps(), new NamedParametersSteps());
    }
     
    @Override
    protected List<String> storyPaths() {
        // Specify story paths as URLs
        String codeLocation = codeLocationFromClass(this.getClass()).getFile();
        return new StoryFinder().findPaths(codeLocation, asList("**/trader_is_alerted_of_status.story",
                "**/traders_can_be_subset.story"), asList(""), "file:" + codeLocation);
    }
         
}



JUnit AnnotatedEmbedderRunner

JBehave also provides an implementation of JUnit's Runner, AnnotatedEmbedderRunner, which is runnable via JUnit's @RunWith annotation:

Code Block
languagejava
titleAnnotatedEmbedderRunner
collapsetrue
@RunWith(AnnotatedEmbedderRunner.class)
@Configure(storyLoader = MyStoryLoader.class, storyReporterBuilder = MyReportBuilder.class, 
        parameterConverters = { MyDateConverter.class })
@UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = true, ignoreFailureInView = true)
@UsingSteps(instances = { TraderSteps.class, BeforeAfterSteps.class, AndSteps.class, CalendarSteps.class,
        PriorityMatchingSteps.class, SandpitSteps.class })
public class TraderAnnotatedEmbedder implements Embeddable {
 
    private Embedder embedder;
 
    public void useEmbedder(Embedder embedder) {
        this.embedder = embedder;
    }
 
    @Test
    public void run() {
        embedder.runStoriesAsPaths(new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(),
                asList("**/*.story"), asList("")));
    }


Integration with other frameworks

As remarked above, JBehave does not impose any tie-in with any framework to run stories. It only requires access to the Embedder to run the stories. The following snippet shows, for example, how to use SpringJUnit4ClassRunner to compose and inject steps instances and them the stories:

Code Block
languagejava
titleAnnotatedEmbedderWithSpringJUnit4ClassRunner
collapsetrue
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/org/jbehave/examples/trader/spring/steps.xml" })
public class AnnotatedEmbedderWithSpringJUnit4ClassRunner {
 
    @Autowired
    private TraderSteps traderSteps;
 
    @Autowired
    private BeforeAfterSteps beforeAndAfterSteps;
 
    @Test
    public void runStoriesAsPaths() {
        embedder().runStoriesAsPaths(storyPaths());
    }
 
    @Test
    public void findMatchingCandidateSteps() {
        embedder().reportMatchingStepdocs("When traders are subset to \".*y\" by name");
        embedder().reportMatchingStepdocs("Given a step that is not matched");
    }
 
    private Embedder embedder() {
        Embedder embedder = new ClasspathTraderEmbedder();
        embedder.useStepsFactory(new InstanceStepsFactory(embedder.configuration(), traderSteps, beforeAndAfterSteps));
        return embedder;
    }
 
    protected List<String> storyPaths() {
        StoryFinder finder = new StoryFinder();
        return finder.findPaths(codeLocationFromClass(this.getClass()).getFile(), asList("**/*.story"), asList(""));
    }
 
}


Run Stories 

JBehave provides fully annotatation-based support for specifying configuration and dependency injection. The running stories will go into more details of the different ways to run stories. Or if you want to learn more about JBehave's step matching mechanism, you'll want to explore the concept of candidate steps in more detail.

https://jbehave.org/reference/stable/running-stories.html


Running Stories

JBehave is designed to be embedded in different development environments. The JBehave Core module contains support for running stories as JUnit tests - which can be run either in your favourite IDE or in your command-line build that supports JUnit tests. Other unit testing frameworks, e.g. TestNG or Spring Test, can also be used very easily, c.f. FAQ.

...

Code Block
languagejava
titleTraderStoryRunner
collapsetrue
public class TraderStoryRunner {
 
    @Test
    public void runClasspathLoadedStoriesAsJUnit() {
        // Embedder defines the configuration and candidate steps
        Embedder embedder = new TraderEmbedder();
        List<String> storyPaths = ... // use StoryFinder to look up paths
        embedder.runStoriesAsPaths(storyPaths);
    }
 
    @Test
    public void runURLLoadedStoriesAsJUnit() {
        // Embedder defines the configuration and candidate steps
        Embedder embedder = new URLTraderEmbedder();
        List<String> storyPaths = ... // use StoryFinder to look up paths
        embedder.runStoriesAsPaths(storyPaths);
    }
 
}


where the TraderEmbedder/URLTraderEmbedder define the configuration using the loading from the classpath and URL resources, respectively. E.g.:


Code Block
languagejava
titleTraderEmbedder
collapsetrue
public class TraderEmbedder extends Embedder {
 
    @Override
    public EmbedderControls embedderControls() {
        return new EmbedderControls().doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
    }
 
    @Override
    public Configuration configuration() {
        Class<? extends TraderEmbedder> embedderClass = this.getClass();
        return new MostUsefulConfiguration()
            .useStoryLoader(new LoadFromClasspath(embedderClass.getClassLoader()))
            .useStoryReporterBuilder(new StoryReporterBuilder()
                .withCodeLocation(CodeLocations.codeLocationFromClass(embedderClass))
                .withDefaultFormats()
                .withFormats(CONSOLE, TXT, HTML, XML)
                .withCrossReference(new CrossReference()))
            .useParameterConverters(new ParameterConverters()
                    .addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")))) // use custom date pattern
            .useStepPatternParser(new RegexPrefixCapturingPatternParser(
                            "%")) // use '%' instead of '$' to identify parameters
            .useStepMonitor(new SilentStepMonitor());                               
    }
 
    @Override
    public InjectableStepsFactory stepsFactory() {
        return new InstanceStepsFactory(configuration(), new TraderSteps(new TradingService()), new BeforeAfterSteps());
    }
 
}


Running Remote Stories

JBehave supports running both local and remote stories. To run remote stories, we need to use a URL-based loader with an appropriate remote code location. The difference w.r.t. the local run is minimal:


Code Block
languagejava
titleRemoteTraderStories
collapsetrue
public class RemoteTraderStories extends TraderStories {
 
    @Override
    public Configuration configuration() {
        return super.configuration()
               .useStoryLoader(new LoadFromURL())
               .useStoryReporterBuilder(
                       new StoryReporterBuilder()
                           .withCodeLocation(codeLocationFromURL("http://jbehave.org/reference/examples/stories/"))
                           .withDefaultFormats()
                           .withFormats(CONSOLE, TXT, HTML, XML));
    }
 
    @Override
    protected List<String> storyPaths() {
        // Specify story paths as remote URLs
        String codeLocation = codeLocationFromURL("http://jbehave.org/reference/examples/stories/")
                .toExternalForm();
        return asList(codeLocation + "and_step.story");
    }
 
}


Ignoring Failures Running Stories

By default, the story runners are configured to fail-fast, i.e. the execution will stop at first failed story (but will complete execution of the all the scenarios in the story first). To allow the generation of a complete stories view (reporting how many stories failed), the runners need to be enabled to run stories with ignoreFailureInStories flag set to true. In this way, all stories will run and the failure will be assessed only during the view generation. If any stories failed, the build will fail correspondingly. Should the need to ignore failure in the view arise (although generally not recommended), one can set the ignoreFailureInView flag to true.

View Reports 

https://jbehave.org/reference/stable/reporting-stories.html

...

The StoryReporterBuilder allows to configure multiple story reporters with pre-configured formats: CONSOLE, TXT, HTML, HTML_TEMPLATE and XML.


JBehave tips 


create JBehave REST api templates in Groovy dynamically to eliminate custom mappings for each BDD test - only need self documenting BDD scripts that are dynamically loaded to Groovy smart BDD test classes








Step-by-step guide for Example


Info


sample code block

Code Block
languagetext
titlesample code block
linenumberstrue
collapsetrue



Recommended Next Steps



Page Properties
hiddentrue


Related issues


...