Selenium Data Driven Framework : Running Test In Different Browsers

We have Implemented loadWebBrowser() and  closeWebBrowser() functions In PREVIOUS POST to centralize browser loading activity. Now supposing you wants to run your webdriver  test In any other browser like Google Chrome then how will you do It? Our framework should have some facility to run selenium webdriver  test In your desired browser. Let us do It.


STEP 24
Prerequisite : All previous selenium data driven framework creation steps should be Implemented. All previous steps link are given on THIS PAGE.

To run your selenium webdriver test In some other browser, We have to modify our loadWebBrowser() function. Also we have to create properties file In our project to store the browser name In which browser you wants to run your test. We will use It to store other properties too.

Download Required Files
You need total 4 files for this step.
  1. SuiteBase.java
  2. Param.properties
  3. chromedriver.exe
  4. IEDriverServer.exe
To run your test In Google Chrome or Internet Explorer browser, You have to download Chrome driver "chromedriver.exe" and Internet Explorer Driver "IEDriverServer.exe" files. You can download both .exe files from THIS PAGE In zipped format. 

You can get latest version of  "chromedriver.exe" file from THIS PAGE and "IEDriverServer.exe" from THIS PAGE too.

You need modified SuiteBase.java file, and need to add newly created Param.properties file to run your test on Chrome or Firefox or Internet Explorer browser. You will get both files by downloading bellow given zip folder.
So now you have all required 4 files. Copy paste them as described bellow.
  • Paste SuiteBase.java file on com.stta.TestSuiteBase Package.
  • Paste Param.properties file on com.stta.property Package.
  • Create new folder with name = "BrowserDrivers" under your project and put "chromedriver.exe" and "IEDriverServer.exe" Inside It.
Now your directory structure will looks like bellow.


Now you can run your webdriver test on your required browser. Only you have to change testBrowser name In Param.properties file. 

  • Set testBrowser = Mozilla to run your test In Mozilla Firefox browser.
  • Set testBrowser = Chrome to run your test In Google Chrome browser.
  • Set testBrowser = IE to run your test In Internet Explorer browser.
I have modified loadWebBrowser() and closeWebBrowser() functions In SuiteBase.java file. Now  loadWebBrowser() function will check the existence of previous opened browser. If any previous webdriver browser Instance Is exist then your test will be executed In that Instance otherwise It will create new Instance.


Note : If you wants to run all your tests In single browser Instance then remove closeWebBrowser(); from @AfterTest method of all four test cases. Now your all tests will run In single browser Instance.

How to run WebDriver test on Mozilla Firefox Browser
  • Open Param.properties file In eclipse and set testBrowser=Mozilla and save file.
  • Double click on "Run Test.bat" file from desktop to run test suites.
Test suites will be executed In Mozilla Firefox browser.

How to run WebDriver test on Google Chrome Browser
  • Open Param.properties file In eclipse and set testBrowser=Chrome and save file.
  • Double click on "Run Test.bat" file from desktop to run test suites.
Test suites will be executed In Google Chrome browser.

How to run WebDriver test on Internet Explorer Browser
  • Open Param.properties file In eclipse and set testBrowser=IE and save file.
  • Double click on "Run Test.bat" file from desktop to run test suites.
Test suites will be executed In Internet Explorer browser.

So now you can manage your test browser from Param.properties file. You can set your required browser In Param.properties file then all your tests will run In that specific browser.

3 comments:

  1. I kept,
    testBrowser=IE
    testBrowser=Mozilla
    testBrowser=Chrome , 3 browsers in param.properties but test cases are executing only in chrome browser

    ReplyDelete
  2. I Kept

    testBrowser=ie in param.properties but test cases are excuting only in firefox...

    ReplyDelete
  3. Hi,
    For Me Test cases are not executed in any of the browser. Can you help me out

    ReplyDelete