How to Debug in Selenium | Breakpoints in Automation Testing

Breakpoints in Selenium

Breakpoints in Selenium are used to check the execution of your code. Whenever you implement a breakpoint in your code, the execution will stop right there. This helps you to verify that your code is working as expected. Breakpoints in Selenium helps in debugging. Breakpoints are usually shown in the UI along with the source code.

Methods to Implement Breakpoints in Selenium

There are two methods to set breakpoints in Selenium WebDriver:

  • In the first method,
  • Right click on the command and select the ‘Toggle Breakpoint’. You can also use shortcut key “B” from the keyboard.
  • You can set a breakpoint just before the Test Case you want to examine.
  • After setting breakpoints, click on the Run button to run the test case from the start to the breakpoint.
  • Repeat the same step to deselect the Breakpoint.
  • In the second method,
  • Select Menu Bar -> ‘Actions’ -> select the Toggle Breakpoint. To deselect repeat the same step.

How to Implement Breakpoints in Selenium

To demonstrate, let us consider the following scenario. Validate ‘username’ and ‘password’ when clicked on the ‘Sign in’ button.

First Method

Step 1) Open Selenium IDE and browser

Launch Firefox and Selenium IDE

Step 2) Enter the base URL

Type the Base URL as —> http://demo.guru99.com/test/newtours/

Step 3) Click on the Record button

Navigate to the record button marked in the red box as shown in the screenshot below

Implement Breakpoints In Selenium

Step 4) Toggle the Breakpoint

  1. Under the tab “Table” right click on the command ( “clickandwait”)
  2. Under the “Command” column select the ‘Toggle Breakpoint’. You can also use the shortcut key “B” from the keyboard.

Implement Breakpoints In Selenium

When you toggle breakpoint, it will open another window as shown below. You will see two yellow pipes mark, in front of “clickandwait”, under ‘Command’ column.

Implement Breakpoints In Selenium

It indicates two things,

  • The yellow pipe shows that the test case was paused at that point. So when you click the ‘Run’ button, the execution starts from the beginning of the test case to this point. After that, one need to start executing manually.
  • A Test Script can have multiple breakpoints which can be set in the same manner as shown above.

Second Method

Step 1) Follow the above steps 1, 2 & 3 mentioned in the First method.

Step 2) In this step,

  1. Click on option ‘Actions’ from Menu bar and
  2. Click on the option “Toggle Breakpoint”.

Implement Breakpoints In Selenium

This is all about the breakpoints in Selenium.

Start Point in Selenium

In Selenium, Start Point indicates the point from where the execution should begin. Start Point can be used when you want to run the testscript from the middle of the code or a breakpoint.

To understand this, let us take an example of the login scenario. Suppose, if you have to login into the website and perform series of tests and then try to debug one of those tests.

In this case, you have to login once and then re-run your tests as you are developing them. You can set the Start Points after login function. So everytime you perform a new test it will begin executing after the login function.

Methods to set Start Point in Selenium

Start Point can be selected by two methods:

1. Right click on any command under the ‘Command’ column in selenium IDE. Select the option ‘Set/clear Start Point ‘. You can also use the shortcut key ‘S’ from the keyboard to mark the start point (shown as a green triangle in the screen shot). Repeat the same step to deselect the Start Point .

2. Click “Actions” -> ‘Set/Clear Start Point ‘. This will select the Start Point or repeat the same step to deselect them.

How to Set Start Point in Selenium

Let see the first method with an example:

First Method

Step 1) Launch Firefox and Selenium IDE.

Step 2) Type the Base URL as —> http://demo.guru99.com/test/newtours/

Step 3) Click on the Record button (marked in red rectangle box in the

the screen shot below).

Set Start Point In Selenium

Step 4) In this step,

  1. Under the tab “Table” right click on the command “clickandwait”
  2. Now select the option ‘Set/Clear Start Point ‘. You can also use the short key “S” from the keyboard to select the same Set/Clear Start Point .

Set Start Point In Selenium

When you click on Set/ Clear Start Point, it will open another window. In this window, you can see the green Triangle symbol before “type” under ‘Command’ column.

This triangle symbol indicates that the test case starts at this point. So

when you click ‘Run’ button, the execution starts from that point onwards.

Set Start Point In Selenium

Note: There can only be one Start Point in a single test script. Also, Start Point is dependent on the currently displayed page. The execution will fail if the user is on the wrong page.

Second Method

  1. Follow the above steps 1, 2 & 3 mentioned in previous (First) method.
  2. Next, follow the following steps,
  1. Click on option ‘Actions’ from Menu bar and
  2. Click on the option “Set/Clear Start Point “.

Set Start Point In Selenium

Summary

  • Breakpoints and Start Point feature help in the debugging process. It helps to start or pause any given test at a particular point of instance. This helps to observe the behavior of the test script.
  • In a single test script, there can only be one Start Point as compared to many Breakpoints.