Search code examples
testingseleniumfunctional-testing

Set system date for selenium tests


I have a Javascript script that should work on weekends and at nights and I want to test it with Selenium (yeah, I know about Jasmine, it's just easier to use Selenium for this project).

Is it possible to somehow change system (browser) dates to test the script without writing setters in the script for testing?


Solution

  • There is a way to do it Selenium way....You can invoke/Execute the Javascript functions Synchronously and Async way....

    IWebDriver driver = new InternetExplorerDriver();
    driver.Navigate().GoToUrl("http://www.google.com");
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    

    Synchronous way

    js.ExecuteAsyncScript("Javascript_Function(Date_x,Time_Y)");
    

    Async - Way

    js.ExecuteScript("Javascript_Function(Date_x,Time_Y)");
    

    I hope this helps...all the best :)