Sunday, 6 May 2018

JavaFX Tutorial

      Introduction to JavaFX
      Hello World Application
      Application Thread
      JavaFX: Print multiplication table

UI Controls

      JavaFX UI Controls
            Working with Label widget
                  Set label text color
                  Set gap between text and graphic image
                  Align label text
                  setContentDisplay: Set the position of graphic relative to text
                  setFont: Set label font
                  Wrapping up the text
                  Render big strings in limited space
                  Applying Effects
                  Event handling
            Working with Button widget
                  Create button
                  setGraphic: Add icon to a button
                  Perform action on button click
                  Add affects to a button
                  Add style to a button using style sheet
            Working with Radio button widget
                  Create Radio button
                  Select the radio button by default
                  How to check whether radio button is selected or not
                  Add an image to radio button
                  Grouping radio buttons
                  Event handling for radio buttons
            Toggle Button
                  Create Toggle Button
                  Add toggle buttons to a group
                  Set behavior to toggle button
                  Apply css styles to toggle button
            Working with check boxes
                  Create check box
                  Select the checkbox by default
                  States of checkbox
                  Event handling
            ChoiceBox widget
                  Create ChoiceBox
                  Add separator between choice elements
                  Set tooltip to choice box
                  Set the behavior to choice box
            TextField widget
                  Create TextField widget
                  Set prompt text
                  Form example using GridPane
                  Processing text field data
                  Clear the text field
            Store password
                  ScrollBar widget
                  Create scroll bar
                  Handling scrollbar events
            ScrollPane widget
                  Create scroll pane
                  Add horizontal and vertical scrollbars to scroll pane
                  Handling ScrollPane events
            ListView
                  Create ListView widget
                  Set height and width of ListView widget
                  Create horizontal ListView
                  ListView Event handling
                  ListView: get the selected item
                  ListView: Select multiple items
                  ListView: get list of multiple selected items
                  ListView: populating list view with data
                  Populate listview data using ComboBoxListCell
                  Customize ListCell
            TableView Widget
                  Create table
                  Hide columns of a table
                  Add nested columns to a table
                  Add data to a table
                  Adding new rows to a table
                  Edit data in a table
            TreeView Widget
                  Create Tree Views
                  Expand the TreeItem
                  Working with Cell Factory
                  Edit Tree
                  Add new tree items to tree
                  Working with Tree Cell Editors
            Working with TreeTableView widget
                  TreeTableView: Create Tree Table
                  Adding multiple columns
                  Show or hide table columns
                  Hide the root element
                  Enable cell selection
                  Enable multiple selection of rows
            Working with ComboBox widget
                  ComboBox: Add items to the combo box dynamically
                  Restrict the number of visible rows
                  ComboBox: Set a value to the combo box
                  Editable combo boxes
                  ComboBox: Set the prompt text of combo box
                  ComboBox: Event handling
            Working with Separator widget
                  Create Separator widget
                  Create vertical separator
            Working with Slider widget
                  Slider: Create Slider widget
                  Slider: Add event handling to slider widget
            ProgressBar: Working with progress bar
                  ProgressBar: Inderterminate progress bar
                  Working with ProgressIndicator widget
                  ProgressIndicator: Inderterminate progress bar
            Hyperlink widget

Previous                                                 Next                                                 Home

Saturday, 5 May 2018

Gherkin: Doc Strings

If the text is not fit into single line, then you can put that text in
""" Large Text """.

Unsubscribe.feature
Feature: User unsubscription

 Scenario: Unsubscribe the user
  If the subscribed user want to unsubscribe from the application, he/she should be unsubscribed and a mail should be sent.
  
  Given I am a subscribed user
  When I choose to unsubscribe
  Then I should be unsubscribed
  And I should receive an email containing
  """
   Dear User,
   
    You are successfully unsubscribed.
    
   Best Regards
  """

Cucumber generates below skelton.
@Given("^I am a subscribed user$")
public void i_am_a_subscribed_user() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I choose to unsubscribe$")
public void i_choose_to_unsubscribe() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be unsubscribed$")
public void i_should_be_unsubscribed() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should receive an email containing$")
public void i_should_recevie_an_email_containing(String arg1) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}





Previous                                                 Next                                                 Home

Gherkin: Add multiple tables to scenario outline

To improve readability, you can group the examples of scenario outline.
BalGame.feature
Feature: Bal game
 
 Scenario Outline: Remove balls from the box
 
  Given A box of <noOfBalls>
  When I taken <noOfBallsTaken> balls out of the box
  Then <remainingBalls> balls remaining in the box

  Examples: Positive Scenario
   | noOfBalls | noOfBallsTaken | remainingBalls |
   |   100     |     10         |    90          |
   |   200     |     20         |    180         |
   |   100     |     30         |    70          |
   
  Examples: Negative Scenario, user tries to take more balls than total number of balls,
            then it should give all the balls in the box and remainingballs should be 0.
   | noOfBalls | noOfBallsTaken | remainingBalls |
   |   100     |     101        |    0           |
   |   200     |     300        |    0           |
   |   100     |     500        |    0           | 


As you observe the feature file, all the positive scenarios and negative scenarios are grouped separately.

BoxUtil.java
package com.sample.util;

public class BoxUtil {

 public static int getRemainingBalls(int noOfBalls, int noOfBallsTaken) {
  if (noOfBalls < noOfBallsTaken) {
   return 0;
  }
  return noOfBalls - noOfBallsTaken;
 }
}

BallGameTest.java
package com.sample.test;

import static org.junit.Assert.assertEquals;

import com.sample.util.BoxUtil;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class BallGameTest {
 int totalNoOfBalls;
 int ballsTaken;
 
 @Given("^A box of (\\d+)$")
 public void a_box_of(int arg1) throws Exception {
  this.totalNoOfBalls = arg1;
 }

 @When("^I taken (\\d+) balls out of the box$")
 public void i_taken_balls_out_of_the_box(int arg1) throws Exception {
  this.ballsTaken = arg1;
 }

 @Then("^(\\d+) balls remaining in the box$")
 public void balls_remaining_in_the_box(int arg1) throws Exception {
  assertEquals(arg1, BoxUtil.getRemainingBalls(totalNoOfBalls, ballsTaken));
 }

}

TestRun.java
package com.sample.main;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true, features = "src/test/java/com/sample/features", glue = "com.sample.test", plugin = {
  "pretty" })
public class TestRun {

}

When I ran above application, I seen below message in console.
Feature: Bal game

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:3
    Given A box of <noOfBalls>
    When I taken <noOfBallsTaken> balls out of the box
    Then <remainingBalls> balls remaining in the box

    Examples: Positive Scenario

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:11
    Given A box of 100                        # BallGameTest.a_box_of(int)
    When I taken 10 balls out of the box      # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 90 balls remaining in the box        # BallGameTest.balls_remaining_in_the_box(int)

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:12
    Given A box of 200                        # BallGameTest.a_box_of(int)
    When I taken 20 balls out of the box      # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 180 balls remaining in the box       # BallGameTest.balls_remaining_in_the_box(int)

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:13
    Given A box of 100                        # BallGameTest.a_box_of(int)
    When I taken 30 balls out of the box      # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 70 balls remaining in the box        # BallGameTest.balls_remaining_in_the_box(int)

    Examples: Negative Scenario, user tries to take more balls than total number of balls,
            then it should give all the balls in the box and remainingballs should be 0.

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:18
    Given A box of 100                        # BallGameTest.a_box_of(int)
    When I taken 101 balls out of the box     # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 0 balls remaining in the box         # BallGameTest.balls_remaining_in_the_box(int)

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:19
    Given A box of 200                        # BallGameTest.a_box_of(int)
    When I taken 300 balls out of the box     # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 0 balls remaining in the box         # BallGameTest.balls_remaining_in_the_box(int)

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:20
    Given A box of 100                        # BallGameTest.a_box_of(int)
    When I taken 500 balls out of the box     # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 0 balls remaining in the box         # BallGameTest.balls_remaining_in_the_box(int)

6 Scenarios (6 passed)
18 Steps (18 passed)
0m0.295s



Previous                                                 Next                                                 Home

Data tables vs scenario outline

Data tables deals with data that is attached to single step, where as in scenario outline, each row will be executed against complete scenario.

Is place holders in the table should follow the order?
Order of place holder doesn’t matter. Only column headers matter.

Feature: Example of Scenario_outline
 
 Scenario Outline: Remove balls from the box
 
  Given A box of <noOfBalls>
  When I taken <noOfBallsTaken> balls out of the box
  Then <remainingBalls> balls remaining in the box

  Examples:
   | noOfBalls | noOfBallsTaken | remainingBalls |
   |   100     |     10         |    90          |
   |   200     |     20         |    180         |
   |   100     |     30         |    70          |

We can represent above scenario like below.

Feature: Example of Scenario_outline
 
 Scenario Outline: Remove balls from the box
 
  Given A box of <noOfBalls>
  When I taken <noOfBallsTaken> balls out of the box
  Then <remainingBalls> balls remaining in the box

  Examples:
      | noOfBallsTaken | noOfBalls | remainingBalls |
      |     10         |  100      |    90          |
      |     20         |  200       |    180         |
      |     30         |  100      |    70          |

As you see the Examples: section, column names are not in the order of the test steps.


Previous                                                 Next                                                 Home

Friday, 4 May 2018

Comment multiple lines in Eclipse

Previous                                                    Next                                                    Home

Cucumber: Scenario outline

If multiple scenarios are following same steps, but with different inputs and different outputs, then we can model them using scenario outline in efficient way.

Let me explain with an example.

BallGame.feature
Feature: Example of Scenario_outline

 Scenario: Remove 10 balls from the box
 
  Given A box of 100 balls
  When I taken 10 balls out of the box
  Then 90 balls remaining in the box
  
 Scenario: Remove 20 balls from the box
 
  Given A box of 200 balls
  When I taken 20 balls out of the box
  Then 180 balls remaining in the box
  
 Scenario: Remove 30 balls from the box
 
  Given A box of 100 balls
  When I taken 30 balls out of the box
  Then 70 balls remaining in the box
As you closely observe above scenarios, all these three scenarios following same steps.

By using Scenario Outline, Examples with tables and < > delimited parameters, we can rewrite above feature file in more compact and efficient way.

BallGame.feature

Feature: Example of Scenario_outline
 
 Scenario Outline: Remove balls from the box
 
  Given A box of <noOfBalls>
  When I taken <noOfBallsTaken> balls out of the box
  Then <remainingBalls> balls remaining in the box

  Examples:
   | noOfBalls | noOfBallsTaken | remainingBalls |
   |   100     |     10         |    90          |
   |   200     |     20         |    180         |
   |   100     |     30         |    70          |


Gherkin generates below Skelton for above feature file. I used place holders in the scenario outline using <> (Angular brackets). Real values in the Examples, are substituted in scenario outline steps.

@Given("^A box of (\\d+)$")
public void a_box_of(int arg1) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I taken (\\d+) balls out of the box$")
public void i_taken_balls_out_of_the_box(int arg1) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^(\\d+) balls remaining in the box$")
public void balls_remaining_in_the_box(int arg1) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

Find the below working application.

BoxUtil.java

package com.sample.util;

public class BoxUtil {

 public static int getRemainingBalls(int noOfBalls, int noOfBallsTaken){
  return noOfBalls - noOfBallsTaken;
 }
}

BallGameTest.java
package com.sample.test;

import static org.junit.Assert.assertEquals;

import com.sample.util.BoxUtil;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class BallGameTest {
 int totalNoOfBalls;
 int ballsTaken;
 
 @Given("^A box of (\\d+)$")
 public void a_box_of(int arg1) throws Exception {
  this.totalNoOfBalls = arg1;
 }

 @When("^I taken (\\d+) balls out of the box$")
 public void i_taken_balls_out_of_the_box(int arg1) throws Exception {
  this.ballsTaken = arg1;
 }

 @Then("^(\\d+) balls remaining in the box$")
 public void balls_remaining_in_the_box(int arg1) throws Exception {
  assertEquals(arg1, BoxUtil.getRemainingBalls(totalNoOfBalls, ballsTaken));
 }

}


TestRun.java

package com.sample.main;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true, features = "src/test/java/com/sample/features", glue = "com.sample.test", plugin = {
  "pretty" })
public class TestRun {

}

When you ran the application as junit test, you can get below messages in console.

Feature: Example of Scenario_outline

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:3
    Given A box of <noOfBalls>
    When I taken <noOfBallsTaken> balls out of the box
    Then <remainingBalls> balls remaining in the box

    Examples: 

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:11
    Given A box of 100                        # BallGameTest.a_box_of(int)
    When I taken 10 balls out of the box      # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 90 balls remaining in the box        # BallGameTest.balls_remaining_in_the_box(int)

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:12
    Given A box of 200                        # BallGameTest.a_box_of(int)
    When I taken 20 balls out of the box      # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 180 balls remaining in the box       # BallGameTest.balls_remaining_in_the_box(int)

  Scenario Outline: Remove balls from the box # src/test/java/com/sample/features/BallGame.feature:13
    Given A box of 100                        # BallGameTest.a_box_of(int)
    When I taken 30 balls out of the box      # BallGameTest.i_taken_balls_out_of_the_box(int)
    Then 70 balls remaining in the box        # BallGameTest.balls_remaining_in_the_box(int)

3 Scenarios (3 passed)
9 Steps (9 passed)
0m0.266s



Previous                                                 Next                                                 Home