Test Framework For Selenium WebDriver : Implement Load Browser Function

As you know, We have already Introduced Selenium webdriver In our test data driven framework during PREVIOUS POST. And now we are going ahead very slowly to use data driven framework In selenium webdriver tests.
STEP 23


Prerequisite : All previous data driven framework creation steps for selenium webdriver should be Implemented. You will get links for all steps at THIS PAGE.

Why Need To Centralize Load Browser Function
If you have looked Inside all four test cases, All four test cases have a same code to open browser, to maximize browser and to set timeout. Right now, We have only 4 test cases In our framework but supposing you have 100 test cases In your real world project then you will repeat same code In all 100 test cases? This Is not good coding practice.. Right..? By centralizing load browser function, We will get bellow given 2 benefits.
  • Using centralized load browser, We can eliminate duplicate code In all test cases. So It will reduce code size.
  • In future, If you wants to change any thing In open browser function, You can do It easily from one place. Supposing you wants to change timeout from 15 seconds to 20 seconds then you have to modify code at only one place and It will be applied everywhere.
How To Do It?
We will create one common function loadWebBrowser() In SuiteBase.java file and then will call It In all test cases.

What loadWebBrowser() Will Do?
loadWebBrowser() function will be useful to handle bellow given things.
  • To open the new browser Instance.
  • To maximize browser.
  • To apply Implicit wait for test.
In Next step, We will also Implement functionality to run your tests In other browsers like Google chrome and Internet Explorer and how to manage It from one place.

I have also Implemented closeWebBrowser() function and used It Inside @AfterTest method of all test cases to close browser after test case execution.

Download Required Files
I have modified all test cases and SuiteBase.java files to Implement loadWebBrowser() and  closeWebBrowser() functions. You will get all files by downloading bellow given zip folder.
Extract the folder and copy-paste all files on respective packages of "WDDF" project to replace existing files.

Run Test And Observe Result
Double click on "Shortcut to Run Test.bat" file to run test. Observe test execution and results.

1 comment:

  1. hi am getting an error
    org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
    Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
    System info: host: 'KDC-DTP-003', ip: '192.168.4.223', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
    Driver info: driver.version: FirefoxDriver

    when i execute.

    Please Help,

    ReplyDelete