Skip to content

Commit e00d7d7

Browse files
authored
Add additional logging for actions on elements to resolve #76 (#105)
* Add additional logging for actions on elements to resolve #76 * #76 Fix russian localized values
1 parent 1c6e1d4 commit e00d7d7

File tree

16 files changed

+99
-70
lines changed

16 files changed

+99
-70
lines changed

Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Aquality.Selenium.Browsers
44
{
55
/// <summary>
6-
/// Abstract representation of <see cref="Aquality.Selenium.Browsers.IBrowserFactory"/>.
6+
/// Abstract representation of <see cref="IBrowserFactory"/>.
77
/// </summary>
88
public abstract class BrowserFactory : IBrowserFactory
99
{

Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void SetDefaultFactory()
6464
/// <summary>
6565
/// Sets custom browser factory.
6666
/// </summary>
67-
/// <param name="browserFactory">Custom implementation of <see cref="Aquality.Selenium.Browsers.IBrowserFactory"/></param>
67+
/// <param name="browserFactory">Custom implementation of <see cref="IBrowserFactory"/></param>
6868
public static void SetFactory(IBrowserFactory browserFactory)
6969
{
7070
browserFactoryContainer.Value = browserFactory;

Aquality.Selenium/src/Aquality.Selenium/Browsers/IBrowserFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Aquality.Selenium.Browsers
22
{
33
/// <summary>
4-
/// Factory that creates instance of desired Browser based on <see cref="Aquality.Selenium.Configurations.IConfiguration"/>.
4+
/// Factory that creates instance of desired Browser based on <see cref="Configurations.IConfiguration"/>.
55
/// </summary>
66
public interface IBrowserFactory
77
{

Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/CheckBoxJsActions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Aquality.Selenium.Browsers;
22
using Aquality.Selenium.Elements.Interfaces;
3-
using Aquality.Selenium.Logging;
43

54
namespace Aquality.Selenium.Elements.Actions
65
{
@@ -19,7 +18,7 @@ public CheckBoxJsActions(IElement element, string elementType) : base(element, e
1918
/// <returns>True if checked and false otherwise.</returns>
2019
public bool GetState()
2120
{
22-
Logger.InfoLoc("loc.checkbox.get.state");
21+
LogElementAction("loc.checkbox.get.state");
2322
return ExecuteScript<bool>(JavaScript.GetCheckBoxState);
2423
}
2524
}

Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/ComboBoxJsActions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public ComboBoxJsActions(IElement element, string elementType) : base(element, e
2020
/// <returns>List of options' texts</returns>
2121
public IList<string> GetTexts()
2222
{
23+
LogElementAction("loc.combobox.get.texts.js");
2324
return ExecuteScript<IList<object>>(JavaScript.GetComboBoxTexts).Select(item => item.ToString()).ToList();
2425
}
2526

@@ -29,6 +30,7 @@ public IList<string> GetTexts()
2930
/// <returns>Selected option text.</returns>
3031
public string GetSelectedText()
3132
{
33+
LogElementAction("loc.combobox.get.text.js");
3234
return ExecuteScript<string>(JavaScript.GetComboBoxSelectedText);
3335
}
3436

@@ -38,6 +40,7 @@ public string GetSelectedText()
3840
/// <param name="text">Target option.</param>
3941
public void SelectValueByText(string text)
4042
{
43+
LogElementAction("loc.combobox.select.by.text.js", text);
4144
ExecuteScript(JavaScript.SelectComboBoxValueByText, text);
4245
}
4346
}

Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/JsActions.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public void ClickAndWait()
4343
/// </summary>
4444
public void Click()
4545
{
46-
Logger.InfoLoc("loc.clicking.js");
46+
LogElementAction("loc.clicking.js");
4747
HighlightElement();
4848
ExecuteScript(JavaScript.ClickElement);
4949
}
5050

5151
/// <summary>
5252
/// Highlights the element.
53-
/// Default value is from configuration: <see cref="Aquality.Selenium.Configurations.IBrowserProfile.IsElementHighlightEnabled">
53+
/// Default value is from configuration: <see cref="IBrowserProfile.IsElementHighlightEnabled">
5454
/// </summary>
5555
public void HighlightElement(HighlightState highlightState = HighlightState.Default)
5656
{
@@ -65,7 +65,7 @@ public void HighlightElement(HighlightState highlightState = HighlightState.Defa
6565
/// </summary>
6666
public void ScrollIntoView()
6767
{
68-
Logger.InfoLoc("loc.scrolling.js");
68+
LogElementAction("loc.scrolling.js");
6969
ExecuteScript(JavaScript.ScrollToElement, true);
7070
}
7171

@@ -76,7 +76,7 @@ public void ScrollIntoView()
7676
/// <param name="y">Verticale coordinate</param>
7777
public void ScrollBy(int x, int y)
7878
{
79-
Logger.InfoLoc("loc.scrolling.js");
79+
LogElementAction("loc.scrolling.js");
8080
ExecuteScript(JavaScript.ScrollBy, x, y);
8181
}
8282

@@ -85,7 +85,7 @@ public void ScrollBy(int x, int y)
8585
/// </summary>
8686
public void ScrollToTheCenter()
8787
{
88-
Logger.InfoLoc("loc.scrolling.center.js");
88+
LogElementAction("loc.scrolling.center.js");
8989
ExecuteScript(JavaScript.ScrollToElementCenter);
9090
}
9191

@@ -95,7 +95,7 @@ public void ScrollToTheCenter()
9595
/// <param name="value">Value to set</param>
9696
public void SetValue(string value)
9797
{
98-
Logger.InfoLoc("loc.setting.value", value);
98+
LogElementAction("loc.setting.value", value);
9999
ExecuteScript(JavaScript.SetValue, value);
100100
}
101101

@@ -104,7 +104,7 @@ public void SetValue(string value)
104104
/// </summary>
105105
public void SetFocus()
106106
{
107-
Logger.InfoLoc("loc.focusing");
107+
LogElementAction("loc.focusing");
108108
ExecuteScript(JavaScript.SetFocus);
109109
}
110110

@@ -114,7 +114,7 @@ public void SetFocus()
114114
/// <returns>True if element is on screen and false otherwise.</returns>
115115
public bool IsElementOnScreen()
116116
{
117-
Logger.InfoLoc("loc.is.present.js");
117+
LogElementAction("loc.is.present.js");
118118
return ExecuteScript<bool>(JavaScript.ElementIsOnScreen);
119119
}
120120

@@ -124,7 +124,7 @@ public bool IsElementOnScreen()
124124
/// <returns>Text from element</returns>
125125
public string GetElementText()
126126
{
127-
Logger.InfoLoc("loc.get.text.js");
127+
LogElementAction("loc.get.text.js");
128128
return ExecuteScript<string>(JavaScript.GetElementText);
129129
}
130130

@@ -133,7 +133,7 @@ public string GetElementText()
133133
/// </summary>
134134
public void HoverMouse()
135135
{
136-
Logger.InfoLoc("loc.hover.js");
136+
LogElementAction("loc.hover.js");
137137
ExecuteScript(JavaScript.MouseHover);
138138
}
139139

@@ -143,7 +143,7 @@ public void HoverMouse()
143143
/// <returns>String representation of element's XPath locator.</returns>
144144
public string GetXPath()
145145
{
146-
Logger.InfoLoc("loc.get.xpath.js");
146+
LogElementAction("loc.get.xpath.js");
147147
return ExecuteScript<string>(JavaScript.GetElementXPath);
148148
}
149149

@@ -166,5 +166,10 @@ protected void ExecuteScript(JavaScript scriptName, params object[] arguments)
166166
{
167167
Browser.ExecuteScript(scriptName, element.GetElement(), arguments);
168168
}
169+
170+
protected internal void LogElementAction(string messageKey, params object[] args)
171+
{
172+
Logger.InfoLocElementAction(elementType, element.Name, messageKey, args);
173+
}
169174
}
170175
}

Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/MouseActions.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ public MouseActions(IElement element, string elementType)
2323
this.elementType = elementType;
2424
}
2525

26-
private Logger Logger => Logger.Instance;
27-
2826
private JsActions JsActions => new JsActions(element, elementType);
2927

3028
/// <summary>
3129
/// Performs click on element.
3230
/// </summary>
3331
public void Click()
3432
{
35-
Logger.InfoLoc("loc.clicking");
33+
LogElementAction("loc.clicking");
3634
JsActions.HighlightElement();
3735
ElementActionRetrier.DoWithRetry(() => PerformAction(element => MoveToElement(element).Click(element)));
3836
}
@@ -42,7 +40,7 @@ public void Click()
4240
/// </summary>
4341
public void DoubleClick()
4442
{
45-
Logger.InfoLoc("loc.clicking.double");
43+
LogElementAction("loc.clicking.double");
4644
ElementActionRetrier.DoWithRetry(() => PerformAction(element => MoveToElement(element).DoubleClick(element)));
4745
}
4846

@@ -51,7 +49,7 @@ public void DoubleClick()
5149
/// </summary>
5250
public void RightClick()
5351
{
54-
Logger.InfoLoc("loc.clicking.right");
52+
LogElementAction("loc.clicking.right");
5553
ElementActionRetrier.DoWithRetry(() => PerformAction(element => MoveToElement(element).ContextClick(element)));
5654
}
5755

@@ -60,7 +58,7 @@ public void RightClick()
6058
/// </summary>
6159
public void MoveMouseToElement()
6260
{
63-
Logger.InfoLoc("loc.moving");
61+
LogElementAction("loc.moving");
6462
JsActions.ScrollIntoView(); // TODO: check on Safari
6563
ElementActionRetrier.DoWithRetry(() => PerformAction(element => MoveToElement(element)));
6664
}
@@ -74,5 +72,10 @@ private void PerformAction(Func<RemoteWebElement, SeleniumActions> action)
7472
{
7573
action(element.GetElement()).Build().Perform();
7674
}
75+
76+
protected internal void LogElementAction(string messageKey, params object[] args)
77+
{
78+
Logger.Instance.InfoLocElementAction(elementType, element.Name, messageKey, args);
79+
}
7780
}
7881
}

Aquality.Selenium/src/Aquality.Selenium/Elements/CheckBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public bool IsChecked
2121
{
2222
get
2323
{
24-
Logger.InfoLoc("loc.checkbox.get.state");
24+
LogElementAction("loc.checkbox.get.state");
2525
return GetElement().Selected;
2626
}
2727
}
@@ -45,7 +45,7 @@ public void Toggle()
4545

4646
private void SetState(bool state)
4747
{
48-
Logger.InfoLoc("loc.setting.value", state.ToString());
48+
LogElementAction("loc.setting.value", state);
4949
if (state != IsChecked)
5050
{
5151
Click();

Aquality.Selenium/src/Aquality.Selenium/Elements/ComboBox.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Aquality.Selenium.Elements.Actions;
22
using Aquality.Selenium.Elements.Interfaces;
33
using Aquality.Selenium.Localization;
4-
using Aquality.Selenium.Logging;
54
using OpenQA.Selenium;
65
using OpenQA.Selenium.Support.UI;
76
using System.Collections.Generic;
@@ -28,7 +27,7 @@ public IList<string> Texts
2827
{
2928
get
3029
{
31-
Logger.InfoLoc("loc.combobox.get.texts");
30+
LogElementAction("loc.combobox.get.texts");
3231
return DoWithRetry(() => new SelectElement(GetElement()).Options.Select(option => option.Text).ToList());
3332
}
3433
}
@@ -37,7 +36,7 @@ public IList<string> Values
3736
{
3837
get
3938
{
40-
Logger.InfoLoc("loc.combobox.get.values");
39+
LogElementAction("loc.combobox.get.values");
4140
return DoWithRetry(() => new SelectElement(GetElement()).Options.Select(option => option.GetAttribute(Attributes.Value)).ToList());
4241
}
4342
}
@@ -46,7 +45,7 @@ public IList<string> Values
4645

4746
public void SelectByContainingText(string text)
4847
{
49-
Logger.InfoLoc("loc.selecting.value");
48+
LogElementAction("loc.selecting.value");
5049
DoWithRetry(() =>
5150
{
5251
var select = new SelectElement(GetElement());
@@ -65,7 +64,7 @@ public void SelectByContainingText(string text)
6564

6665
public void SelectByContainingValue(string value)
6766
{
68-
Logger.InfoLoc("loc.selecting.value");
67+
LogElementAction("loc.selecting.value");
6968
DoWithRetry(() =>
7069
{
7170
var select = new SelectElement(GetElement());
@@ -84,19 +83,19 @@ public void SelectByContainingValue(string value)
8483

8584
public void SelectByIndex(int index)
8685
{
87-
Logger.InfoLoc("loc.selecting.value");
86+
LogElementAction("loc.selecting.value");
8887
DoWithRetry(() => new SelectElement(GetElement()).SelectByIndex(index));
8988
}
9089

9190
public void SelectByText(string text)
9291
{
93-
Logger.InfoLoc("loc.selecting.value");
92+
LogElementAction("loc.selecting.value");
9493
DoWithRetry(() => new SelectElement(GetElement()).SelectByText(text));
9594
}
9695

9796
public void SelectByValue(string value)
9897
{
99-
Logger.InfoLoc("loc.selecting.value");
98+
LogElementAction("loc.selecting.value");
10099
DoWithRetry(() => new SelectElement(GetElement()).SelectByValue(value));
101100
}
102101
}

Aquality.Selenium/src/Aquality.Selenium/Elements/Element.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,48 +70,48 @@ public void WaitAndClick()
7070

7171
public void Click()
7272
{
73-
Logger.InfoLoc("loc.clicking");
73+
LogElementAction("loc.clicking");
7474
JsActions.HighlightElement();
7575
DoWithRetry(() => GetElement().Click());
7676
}
7777

7878
public void Focus()
7979
{
80-
Logger.InfoLoc("loc.focusing");
80+
LogElementAction("loc.focusing");
8181
JsActions.SetFocus();
8282
}
8383

8484
public string GetAttribute(string attr, HighlightState highlightState = HighlightState.Default)
8585
{
86-
Logger.InfoLoc("loc.el.getattr", attr);
86+
LogElementAction("loc.el.getattr", attr);
8787
JsActions.HighlightElement(highlightState);
8888
return DoWithRetry(() => GetElement().GetAttribute(attr));
8989
}
9090

9191
public string GetCssValue(string propertyName, HighlightState highlightState = HighlightState.Default)
9292
{
93-
Logger.InfoLoc("loc.el.cssvalue", propertyName);
93+
LogElementAction("loc.el.cssvalue", propertyName);
9494
JsActions.HighlightElement(highlightState);
9595
return DoWithRetry(() => GetElement().GetCssValue(propertyName));
9696
}
9797

9898
public string GetText(HighlightState highlightState = HighlightState.Default)
9999
{
100-
Logger.InfoLoc("loc.get.text");
100+
LogElementAction("loc.get.text");
101101
JsActions.HighlightElement(highlightState);
102102
return DoWithRetry(() => GetElement().Text);
103103
}
104104

105105
public void SendKeys(string key)
106106
{
107-
Logger.InfoLoc("loc.text.sending.keys", key);
107+
LogElementAction("loc.text.sending.keys", key);
108108
DoWithRetry(() => GetElement().SendKeys(key));
109109
}
110110

111111
public void SetInnerHtml(string value)
112112
{
113113
Click();
114-
Logger.InfoLoc("loc.send.text", value);
114+
LogElementAction("loc.send.text", value);
115115
Browser.ExecuteScript(JavaScript.SetInnerHTML, GetElement(), value);
116116
}
117117

@@ -129,5 +129,10 @@ protected T DoWithRetry<T>(Func<T> function)
129129
{
130130
return ElementActionRetrier.DoWithRetry(function);
131131
}
132+
133+
protected internal void LogElementAction(string messageKey, params object[] args)
134+
{
135+
Logger.InfoLocElementAction(ElementType, Name, messageKey, args);
136+
}
132137
}
133138
}

0 commit comments

Comments
 (0)