Writing Test Results to Excel using Selenium Writing Test Results to Excel using Selenium selenium selenium

Writing Test Results to Excel using Selenium


Here is the structure as i see it:

1) A part where you have a DriverFactory defined.

public class BrowserFactory {public static WebDriver localDriver(Capabilities capabilities) {String browserType = capabilities.getBrowserName();if (browserType.equals("firefox"))  return new FirefoxDriver(capabilities);if (browserType.startsWith("internet explorer"))  return new InternetExplorerDriver(capabilities);if (browserType.equals("chrome"))  return new ChromeDriver(capabilities);throw new Error("Unrecognized browser type: " + browserType);}

Then you can simply initialize it anytime you need it : Example:

driver = BrowserFactory.localDriver(DesiredCapabilities.firefox());

2) Your test classes, where you use this factory. Then there will be no need in @BeforeClass annotations. You write your tests in those classes. And at the end of every test, you make an assert (if test result failed or not). To check if the test passes, use the Assert.true(); Example: I i use the wrokg credentials on login, the allert: Wrong Password will appear.

Solution: You make an Assert.true(errorMessagePresent)

3) Your output writer class - to make it accessible for your tests

3) In case the test passes - you add the string you want to the output, using the buffer reader, else you throw an exception