Skip to main content

Monochrome in Cucumber

We set the monochrome option to true inside the @CucucmberOptions annotation to remove unreadable characters in the console output during execution. 

This option can either be set to true or false.

Monochrome Method Signature

Method Signature: public abstract boolean monochrome

Returns: whether or not to use monochrome output

Default: false

Example: Monochrome in Cucumber Runner

@RunWith(Cucumber.class)
@CucumberOptions(
		plugin = {"pretty", "html:target/cucumber"},
		features = {"features"},
		glue={"com.pb.cucumbertest.stepdefinitions"},
		monochrome = true
		)

public class Runner {

}

Monochrome False in Cucumber

monochrome default value is false, which means when you do not include the monochrome option in cucumber options or set its value to false. Your output will contain some unnecessary character. Observe in below output [32m, [0m, [90#m characters, these are making output difficult to read for us.

Scenario: Click on login link         [90m# src/test/resources/features/first.feature:4[0m
  [32mGiven [0m[32mI am on the homepage[0m          [90m# com.pb.cucumbertest.stepdefinitions.FirstSD.homepage1()[0m
  [32mAnd [0m[32mI click on login link[0m           [90m# com.pb.cucumbertest.stepdefinitions.FirstSD.i_click_on_login_link()[0m
  [32mThen [0m[32mI should see [0m[32m[1m"My Account"[0m[32m link[0m [90m# com.pb.cucumbertest.stepdefinitions.FirstSD.i_should_see_link(java.lang.String)[0m

Monochrome True in Cucumber

When monochrome value set to true, It will make console output for the Cucumber test much more readable and remove any unreadable character.

Scenario: Click on login link         # src/test/resources/features/first.feature:4
  Given I am on the homepage          # com.pb.cucumbertest.stepdefinitions.FirstSD.homepage1()
  And I click on login link           # com.pb.cucumbertest.stepdefinitions.FirstSD.i_click_on_login_link()
  Then I should see "My Account" link # com.pb.cucumbertest.stepdefinitions.FirstSD.i_should_see_link(java.lang.String)

Now compare the output with above output where monochrome value is set to false, no such unreadable characters are included now.

Video Tutorial: Monochrome in Cucumber

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.