GithubHelp home page GithubHelp logo

blogwatch-1's Introduction

Blog Watch

This project contains UI tests for baeldung.com

Overview

The project uses Selenium framework, Crawler4J, jsoup and REST Assured for UI tests . The tests can be run in GUI or headless mode. UI browser has been configured with Firefox using gecodriver and tested with Firefox 56.0 (64 bit) on Windows. Headless mode works with Chrome and HtmlUnit browsers.

Running Tests from the IDE

The default configuration executes tests with headless mode in Windows environment, target URL is https://www.baeldung.com, and the concurrency level is 3. The configuration can be changed using following properties:

  • spring.profiles.active - environment variable to either "headless-browser" and "ui-browser"
  • target.env - environment variable should be set to "win" or "linux" for headless browser
  • base.url - to target base URL, for example http://www.baeldung.com
  • concurrency.level - parallel threads to request to the target url

These can be set as environment variables via the Eclipse run configuration.

Running Tests Using Maven

Three Maven profiles are available for running tests:

  • headless-browser-windows
  • headless-browser-linux
  • ui-browser-windows

The target URL for all profiles is https://www.baeldung.com, and the concurrency level is 3. This can be changed using following properties:

  • base.url - to target base URL, for example http://www.baeldung.com
  • concurrency.level - parallel threads to request to the target url

Headless Browser selection

Available headless browsers

  • HtmlUnit
  • chrome-headless

Headless browser can be configured using following system property

  • headless.browser.name

MacBook Users

  • In case you are running on MacBook, you will have to download it's specific ChromeDriver version on your own. It can be downloaded from here https://chromedriver.chromium.org.
  • Note there are two versions of chromedriver available for MacBook, depending on processor type (Intel or M1).
  • To match the maven profile for M1 Macbook that exists in pom.xml, you will have to paste the chromedriver under project location bin/mac-m1/.

Updating List of Posts and Pages

Run UpdateArticlesAndPagesLinks#updateLinks test for updating list of articles and pages.

JUnit Tags

Following tags are available for running tests selectively. Refer Java docs in GlobalConstants.java for details

  • hourly
  • daily
  • weekly
  • editorial
  • github-related
  • technical

Excluding a URL for tests running in the bi-monthly build

URLs can be added to the following file to skip a specific test from the bi-monthly build - https://github.com/eugenp/blogwatch/blob/master/src/main/resources/exceptions-for-tests.yaml

Launch Mode

Set environment variable "LAUNCH_FLAG" to either true or false to set launch mode. Default is false

Execution Summary

After all the tests have finished, a test execution summary is logged, with the following format:

============================================================================
Test Execution Summary
============================================================================
Total Failures: X

Executed Tests: Y
testName_1(y1 executions)
testName_2(y2 executions)
...

Failed Tests: Z
failedTest_1(z1 failures)
failedTest_2(z2 failures)
...
=============================End of the Summary===============================

Test execution and test failure counts are automatically collected with the TestMetricsExtension.

For specific situation where this can not be used, we can explicitly collect these numbers inside the test, by invoking:

BaseTest.recordExecution("<TEST_NAME>");
BaseTest.recordFailure("<TEST_NAME>", <COUNT>);

Explicit invocation of these methods is needed in the following situations:

  • the test is annotated with GlobalConstants.TAG_SKIP_METRICS
  • we want to record multiple failures inside the same test
  • the test is invoked from another test (eg: AllUrlsUITest.givenAllTestsRelatedTechnicalArea_whenHittingAllArticles_thenOK)

Parallel Execution of Tests

Currently, concurrency.level property is only in effect for these tests:

Concurrency supported tests are done by extending special base classes:

To perform UI tests on all Articles and Pages concurrently, we can extend our test class from AllUrlsUIBaseTest:

public class ConcurrentTest extends AllUrlsUIBaseTest {

    @ConcurrentTest
    @PageTypes({ SitePage.Type.PAGE, SitePage.Type.ARTICLE })
    @LogOnce("testMethodForAll")
    public final void testMethodForAll(SitePage page) {
        // individual test logic
        // runs for each configured URL in AllUrlsUIBaseTest
        // Different instances of SitePage is provided for each thread
    }

    @ConcurrentTest
    @PageTypes(SitePage.Type.ARTICLE)
    @LogOnce("testMethodOnlyArticles")
    public final void testMethodOnlyArticles(SitePage page) {
        // runs for only articles configured in AllUrlsUIBaseTest
        // here the page parameter has always the type ARTICLE
    }

    @ConcurrentTest
    @PageTypes({ SitePage.Type.PAGE, SitePage.Type.ARTICLE })
    @LogOnce("testBulk")
    public final void testBulk(SitePage page) {
        // We can give already provided page into methods
        testMethod(page);
        // Type specific individual tests must be guarded by the correct type!
        if (AllUrlsConcurrentExtension.ensureTag(page, SitePage.Type.ARTICLE)) {
            testMethodOnlyArticles(page);
        }
    }
}

To run any single test method in parallel, use Maven's test property in the format of -Dtest=<test-class-name>#<method-name>.

An example maven command:

test -Dtest=AllUrlsUITest#givenAllPages_whenAnalysingImages_thenImagesDoNotPoinToTheDraftsSite -Dconcurrency.level=3 -Dheadless.browser.name=chrome-headless -Dbase.url=http://staging8.baeldung.com

On Jenkins

The tests are running here, on Jenkins

Tests

https://docs.google.com/spreadsheets/d/18CcFYAjVmElakaFDzVgLxJ4pyjeKP09BSu9GqG_Uv9U

blogwatch-1's People

Contributors

asif-anwar avatar lor6 avatar ibrahni avatar dangeafer avatar johna1331 avatar collaboratewithakash avatar asjad-j avatar jwpiotrowski avatar eugenp avatar amit2103 avatar kwoyke avatar freelansam avatar corneliulungociu avatar yavuztas avatar rku4er avatar muhammadasim95 avatar mmonik avatar karim-ahshanul avatar sachin29aug avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.