简体   繁体   中英

Regarding Session Timeout using selenium c#

My Application has a Functionality which takes time to load the search results like more then a minute because of which my scripts fails and gives a 60 seconds session timeout error message. I googled few solutions and got one from stack overflow" How to set session timeout in web.config " but i am not sure where exactly to implement it. i have a file in my framework called "app.config" and the code in the app.config is below

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This Below mentioned code is given in the stack overflow to make necessary changes in web.config file to set the session timeout

<configuration>
  <system.web>
     <sessionState timeout="20"></sessionState>
  </system.web>
</configuration>

please help me where to make the necessary changes in app.config file.

You could set an implicit wait for the driver in the following fashion:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

Now the only reason to use app.config is if you want to make this timeout configurable. In which case in your app.config file you would add a section:

<appSettings>
    <add key="driver.Timeout" value="20" />
</appSettings>

Then in your code you would do something like:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(Int32.Parse(ConfigurationManager.AppSettings["driver.Timeout"]));

This way if you deploy your app somewhere and wanted to make the timeout configurable you would just edit your app.config file in a text editor and change the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM