Skip to content

Commit

Permalink
Added Selenium Options Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Dec 30, 2019
1 parent 625c803 commit f1f0ae1
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 5 deletions.
111 changes: 110 additions & 1 deletion taskt/Core/Automation/Commands/SeleniumBrowserElementActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

Expand Down Expand Up @@ -68,7 +69,9 @@ public class SeleniumBrowserElementActionCommand : ScriptCommand
[Attributes.PropertyAttributes.PropertyUISelectionOption("Get Matching Elements")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Wait For Element To Exist")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Switch to frame")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Get Count")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Get Count")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Get Options")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Select Option")]
[Attributes.PropertyAttributes.InputSpecification("Select the appropriate corresponding action to take once the element has been located")]
[Attributes.PropertyAttributes.SampleUsage("Select from **Invoke Click**, **Left Click**, **Right Click**, **Middle Click**, **Double Left Click**, **Clear Element**, **Set Text**, **Get Text**, **Get Attribute**, **Wait For Element To Exist**, **Get Count**")]
[Attributes.PropertyAttributes.Remarks("Selecting this field changes the parameters that will be required in the next step")]
Expand Down Expand Up @@ -261,8 +264,87 @@ where rw.Field<string>("Parameter Name") == "Clear Element Before Setting Text"
}
}

break;
case "Get Options":

string applyToVarName = (from rw in v_WebActionParameterTable.AsEnumerable()
where rw.Field<string>("Parameter Name") == "Variable Name"
select rw.Field<string>("Parameter Value")).FirstOrDefault();


string attribName = (from rw in v_WebActionParameterTable.AsEnumerable()
where rw.Field<string>("Parameter Name") == "Attribute Name"
select rw.Field<string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender);


var optionsItems = new List<string>();
var ele = (IWebElement)element;
var select = new SelectElement(ele);
var options = select.Options;

foreach (var option in options)
{
var optionValue = option.GetAttribute(attribName);
optionsItems.Add(optionValue);
}

var requiredVariable = engine.VariableList.Where(x => x.VariableName == applyToVarName).FirstOrDefault();

if (requiredVariable == null)
{
engine.VariableList.Add(new Script.ScriptVariable() { VariableName = applyToVarName, CurrentPosition = 0 });
requiredVariable = engine.VariableList.Where(x => x.VariableName == applyToVarName).FirstOrDefault();
}

requiredVariable.VariableValue = optionsItems;
requiredVariable.CurrentPosition = 0;


break;
case "Select Option":

string selectionType = (from rw in v_WebActionParameterTable.AsEnumerable()
where rw.Field<string>("Parameter Name") == "Selection Type"
select rw.Field<string>("Parameter Value")).FirstOrDefault();

string selectionParam = (from rw in v_WebActionParameterTable.AsEnumerable()
where rw.Field<string>("Parameter Name") == "Selection Parameter"
select rw.Field<string>("Parameter Value")).FirstOrDefault();


seleniumInstance.SwitchTo().ActiveElement();

var el = (IWebElement)element;
var selectionElement = new SelectElement(el);

switch (selectionType)
{
case "Select By Index":
selectionElement.SelectByIndex(int.Parse(selectionParam));
break;
case "Select By Text":
selectionElement.SelectByText(selectionParam);
break;
case "Select By Value":
selectionElement.SelectByValue(selectionParam);
break;
case "Deselect By Index":
selectionElement.DeselectByIndex(int.Parse(selectionParam));
break;
case "Deselect By Text":
selectionElement.DeselectByText(selectionParam);
break;
case "Deselect By Value":
selectionElement.DeselectByValue(selectionParam);
break;
case "Deselect All":
selectionElement.DeselectAll();
break;
default:
throw new NotImplementedException();
}

break;
case "Get Text":
case "Get Attribute":
case "Get Count":
Expand Down Expand Up @@ -569,7 +651,34 @@ public void seleniumAction_SelectionChangeCommitted(object sender, EventArgs e)
actionParameters.Rows.Add("Variable Name");
}
break;
case "Get Options":
actionParameters.Rows.Add("Attribute Name");
actionParameters.Rows.Add("Variable Name");
break;
case "Select Option":
actionParameters.Rows.Add("Selection Type");
actionParameters.Rows.Add("Selection Parameter");


DataGridViewComboBoxCell selectionTypeBox = new DataGridViewComboBoxCell();
selectionTypeBox.Items.Add("Select By Index");
selectionTypeBox.Items.Add("Select By Text");
selectionTypeBox.Items.Add("Select By Value");
selectionTypeBox.Items.Add("Deselect By Index");
selectionTypeBox.Items.Add("Deselect By Text");
selectionTypeBox.Items.Add("Deselect By Value");
selectionTypeBox.Items.Add("Deselect All");

//assign cell as a combobox
if (sender != null)
{
ElementsGridViewHelper.Rows[0].Cells[1].Value = "Select By Text";
}

ElementsGridViewHelper.Rows[0].Cells[1] = selectionTypeBox;


break;
case "Wait For Element To Exist":
foreach (var ctrl in ElementParameterControls)
{
Expand Down
8 changes: 7 additions & 1 deletion taskt/Core/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public static string ConvertToUserVariable(this String str, object sender)
return string.Empty;

if (sender == null)
return str;
return str;

if (str.Length < 2)
{
return str;
}


var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

Expand Down
3 changes: 2 additions & 1 deletion taskt/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ limitations under the License.
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="OneNoteOCR" version="1.0.0.0" targetFramework="net452" />
<package id="RestSharp" version="106.6.9" targetFramework="net452" />
<package id="Selenium.WebDriver" version="3.7.0" targetFramework="net452" />
<package id="Selenium.Support" version="3.141.0" targetFramework="net48" />
<package id="Selenium.WebDriver" version="3.141.0" targetFramework="net48" />
<package id="Serilog" version="2.7.1" targetFramework="net452" />
<package id="Serilog.Formatting.Compact" version="1.0.0" targetFramework="net452" />
<package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net452" />
Expand Down
7 changes: 5 additions & 2 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@
<Reference Include="UIAutomationClientsideProviders" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
<Reference Include="WebDriver, Version=3.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.7.0\lib\net45\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=3.141.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.141.0\lib\net45\WebDriver.dll</HintPath>
</Reference>
<Reference Include="WebDriver.Support, Version=3.141.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.Support.3.141.0\lib\net45\WebDriver.Support.dll</HintPath>
</Reference>
<Reference Include="WebSocket4Net, Version=0.15.0.9, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocket4Net.0.15.0\lib\net45\WebSocket4Net.dll</HintPath>
Expand Down

0 comments on commit f1f0ae1

Please sign in to comment.