|
|
Hi All,
I have a very basic question related to how to design method for executing selenium GRID.
In current implementation of selenium framework in my project we have created a action class which includes all selenium WebElelement actions in static format. For sequential script execution there is no issue. But for parallel script execution, I heard that we can't design a method as static as only only one copy will be created. Then, how to write custom action method which we can use in other classes.
Could you please advise on this.
Current Implementation:
public class ActionUtil{ public static void selectByVisibleText(WebElement element, String visibleText, String elementName) { try { Select oSelect = new Select(element); oSelect.selectByVisibleText(text); log.info(text + " text is selected on " + elementName); } catch (Exception e) { log.error("selectByVisibleText action failed.Exception occured :" + e.toString()); } } }
Use of 'selectByVisibleText' static method in other page classes:
public void selectMemorableQuestion1(String question) { ActionUtil.selectByVisibleText(memorableQuestion1, question, "memorableQuestion1"); }
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/5013857a-6cbd-43e4-91d4-62da1c1534f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
|
|
Thanks for your reply Jonathan.Could you please share how you implemented this in your code & how you handled log object.
Thanks in advance.
Regards, Abhijit On Tuesday, May 15, 2018 at 3:23:28 PM UTC+5:30, Jonathan Herbaut wrote: Hi Implementing a static method with parallel script is not a problem, the problem is about shared objects. And with your code, the only problem I can eventually see is your log object. Depending on how he is created and deleted, you can have some surprises. I have already writen a method that looks like the same than yours.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9a51b1a9-b51c-4ee8-ab77-addedc1ff02d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
|
|
Here is my code :
private static void SetDataSelectIndex(WebElementValue webElementValue) { var element = webElementValue.Element; var index = (int) webElementValue.Value; try { var select = new SelectElement(element); if (select.Options.IndexOf(select.SelectedOption) != index)
{ select.SelectByIndex(index); } else { } } catch (Exception e) { SeleniumLogger.Instance.Fatal("SetDataSelect", $"Anomalie sur le champ [{element.GetId()}] sur sélection de l'index {index}", e); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); #endif throw; } }
And here is a sample of my SeleniumLogger :
public class SeleniumLogger { private static readonly SiouxSink Sioux = new SiouxSink("TEST", "Selenium"); private static volatile SeleniumLogger s_instance;
private static readonly object s_syncRoot = new Object(); [NotNull]
public static SeleniumLogger Instance { get => s_instance ?? CreateLoggerInstance(); set => s_instance = value; } [Pure, NotNull]
private static SeleniumLogger CreateLoggerInstance() { lock (s_syncRoot) { return s_instance ?? (s_instance = new SeleniumLogger()); } }
public void Fatal(string methodName, string message) { Sioux.Fatal(BasicMessage(methodName, message)); } .... }
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAH1BzpVQ3QhdEGYfRtLRfPPKa1rPgGEbmS7obuEP%2BFz5r9bXkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
|
|
Thanks a Ton Jonathan. I will try to implement this approach.
Regards, Abhijit On Tuesday, May 15, 2018 at 6:49:56 PM UTC+5:30, Jonathan Herbaut wrote: Here is my code :
private static void SetDataSelectIndex(WebElementValue webElementValue) { var element = webElementValue.Element; var index = (int) webElementValue.Value; try { var select = new SelectElement(element); if (select.Options.IndexOf(select.SelectedOption) != index)
{ select.SelectByIndex(index); } else { <a href="http://SeleniumLogger.Instance.Info" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2FSeleniumLogger.Instance.Info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEMJ6BhG9eXpQQMQnrwEzUFGRCfSQ';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2FSeleniumLogger.Instance.Info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEMJ6BhG9eXpQQMQnrwEzUFGRCfSQ';return true;">SeleniumLogger.Instance.Info("SetDataSelect", $"L'index {index} n'impose pas d'action sur le champ [{element.GetId()}]"); } } catch (Exception e) { SeleniumLogger.Instance.Fatal("SetDataSelect", $"Anomalie sur le champ [{element.GetId()}] sur sélection de l'index {index}", e); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); #endif throw; } }
And here is a sample of my SeleniumLogger :
public class SeleniumLogger { private static readonly SiouxSink Sioux = new SiouxSink("TEST", "Selenium"); private static volatile SeleniumLogger s_instance;
private static readonly object s_syncRoot = new Object(); [NotNull]
public static SeleniumLogger Instance { get => s_instance ?? CreateLoggerInstance(); set => s_instance = value; } [Pure, NotNull]
private static SeleniumLogger CreateLoggerInstance() { lock (s_syncRoot) { return s_instance ?? (s_instance = new SeleniumLogger()); } }
public void Fatal(string methodName, string message) { Sioux.Fatal(BasicMessage(methodName, message)); } .... } 2018-05-15 13:33 GMT+02:00 Abhijit Biradar <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="c4FnKdFcBAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">biradar...@...>: Thanks for your reply Jonathan.Could you please share how you implemented this in your code & how you handled log object.
Thanks in advance.
Regards, Abhijit
On Tuesday, May 15, 2018 at 3:23:28 PM UTC+5:30, Jonathan Herbaut wrote:Hi Implementing a static method with parallel script is not a problem, the problem is about shared objects. And with your code, the only problem I can eventually see is your log object. Depending on how he is created and deleted, you can have some surprises. I have already writen a method that looks like the same than yours.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="c4FnKdFcBAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">selenium-user...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="c4FnKdFcBAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">seleniu...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/selenium-users/9a51b1a9-b51c-4ee8-ab77-addedc1ff02d%40googlegroups.com?utm_medium=email&utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/selenium-users/9a51b1a9-b51c-4ee8-ab77-addedc1ff02d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" onclick="this.href='https://groups.google.com/d/msgid/selenium-users/9a51b1a9-b51c-4ee8-ab77-addedc1ff02d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter';return true;">https://groups.google.com/d/msgid/selenium-users/9a51b1a9-b51c-4ee8-ab77-addedc1ff02d%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/99cf97d4-fd4f-43e5-8739-6e5cf35abe10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
|
|