fix connect/disconnect x webDriver (chiude/riapre)
This commit is contained in:
+43
-18
@@ -53,13 +53,13 @@ namespace IOB_WIN
|
||||
public IobWPS(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
||||
{
|
||||
// preparo opzione headless x firefox
|
||||
#if false
|
||||
#if true
|
||||
var o = new FirefoxOptions();
|
||||
o.AddArgument("-headless");
|
||||
driver = new FirefoxDriver(Environment.CurrentDirectory, o);
|
||||
// aggiungo timeout x JScripts
|
||||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
|
||||
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(15);
|
||||
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(15);
|
||||
#endif
|
||||
// impostazione URI di base
|
||||
baseUri = $"http://{IOBConf.cncIpAddr}";
|
||||
@@ -67,11 +67,11 @@ namespace IOB_WIN
|
||||
// test completo funzionalità, da TOGLIERE in prod...
|
||||
baseUri = "https://www.plus2net.com/javascript_tutorial/clock.php";
|
||||
#endif
|
||||
#if false
|
||||
#if true
|
||||
// imposto pagina di acquisizione
|
||||
driver.Navigate().GoToUrl(baseUri);
|
||||
|
||||
#endif
|
||||
|
||||
// inizializzo LUT decodifica
|
||||
string jsonConf = getOptPar("LUT_CONF");
|
||||
if (jsonConf != "")
|
||||
@@ -101,10 +101,15 @@ namespace IOB_WIN
|
||||
try
|
||||
{
|
||||
// in primis chiudo driver...
|
||||
driver.Quit();
|
||||
if (driver != null)
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError(exc, "Eccezione in tryDisconnect");
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// continuo
|
||||
base.stopAdapter(tryRestart, forceDequeue);
|
||||
}
|
||||
@@ -115,23 +120,43 @@ namespace IOB_WIN
|
||||
connectionOk = (testPing() == IPStatus.Success);
|
||||
if (connectionOk)
|
||||
{
|
||||
// preparo opzione headless x firefox
|
||||
var o = new FirefoxOptions();
|
||||
o.AddArgument("-headless");
|
||||
driver = new FirefoxDriver(Environment.CurrentDirectory, o);
|
||||
// aggiungo timeout x JScripts
|
||||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
|
||||
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(15);
|
||||
// imposto pagina di acquisizione
|
||||
driver.Navigate().GoToUrl(baseUri);
|
||||
try
|
||||
{
|
||||
if (driver.SessionId == null)
|
||||
{
|
||||
// preparo opzione headless x firefox
|
||||
var o = new FirefoxOptions();
|
||||
o.AddArgument("-headless");
|
||||
driver = new FirefoxDriver(Environment.CurrentDirectory, o);
|
||||
// aggiungo timeout x JScripts
|
||||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
|
||||
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(15);
|
||||
// imposto pagina di acquisizione
|
||||
driver.Navigate().GoToUrl(baseUri);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError(exc, "Eccezione in tryConnect");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void tryDisconnect()
|
||||
{
|
||||
connectionOk = false;
|
||||
// in primis chiudo driver...
|
||||
driver.Quit();
|
||||
try
|
||||
{
|
||||
// in primis chiudo driver...
|
||||
if (driver != null)
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError(exc, "Eccezione in tryDisconnect");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user