Skip to content

Commit

Permalink
Added Browser Info command to retrieve additional selenium instance data
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jul 27, 2019
1 parent 447da62 commit 2fe9cb8
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(SeleniumBrowserElementActionCommand))]
[XmlInclude(typeof(SeleniumBrowserExecuteScriptCommand))]
[XmlInclude(typeof(SeleniumBrowserSwitchWindowCommand))]
[XmlInclude(typeof(SeleniumBrowserInfoCommand))]
[XmlInclude(typeof(SMTPSendEmailCommand))]
[XmlInclude(typeof(ErrorHandlingCommand))]
[XmlInclude(typeof(StringSubstringCommand))]
Expand Down
113 changes: 113 additions & 0 deletions taskt/Core/Automation/Commands/SeleniumBrowserInfoCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

namespace taskt.Core.Automation.Commands
{



[Serializable]
[Attributes.ClassAttributes.Group("Web Browser Commands")]
[Attributes.ClassAttributes.Description("This command allows you to navigate a Selenium web browser session to a given URL or resource.")]
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to navigate an existing Selenium instance to a known URL or web resource")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements Selenium to achieve automation.")]
public class SeleniumBrowserInfoCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")]
[Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Browser** command")]
[Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")]
[Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Browser** command will cause an error")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_InstanceName { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Indicate which info property to retrieve")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Window Title")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Window URL")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Current Handle ID")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("HTML Page Source")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Handle ID List")]
[Attributes.PropertyAttributes.InputSpecification("Select an option which best fits to the specification you would like to make.")]
[Attributes.PropertyAttributes.SampleUsage("Select one of the provided options.")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_InfoType { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please select the variable to receive the result")]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")]
[Attributes.PropertyAttributes.Remarks("If you have enabled the setting **Create Missing Variables at Runtime** then you are not required to pre-define your variables, however, it is highly recommended.")]
public string v_applyToVariableName { get; set; }
public SeleniumBrowserInfoCommand()
{
this.CommandName = "SeleniumBrowserInfoCommand";
this.SelectionName = "Get Browser Info";
this.v_InstanceName = "default";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
var vInstance = v_InstanceName.ConvertToUserVariable(engine);
var browserObject = engine.GetAppInstance(vInstance);

var seleniumInstance = (OpenQA.Selenium.IWebDriver)browserObject;
var requestedInfo = v_InfoType.ConvertToUserVariable(sender);
string info;

switch (requestedInfo)
{
case "Window Title":
info = seleniumInstance.Title;
break;
case "Window URL":
info = seleniumInstance.Url;
break;
case "Current Handle ID":
info = seleniumInstance.CurrentWindowHandle;
break;
case "HTML Page Source":
info = seleniumInstance.PageSource;
break;
case "Handle ID List":
info = Newtonsoft.Json.JsonConvert.SerializeObject(seleniumInstance.WindowHandles);
break;
default:
throw new NotImplementedException($"{requestedInfo} is not implemented for lookup.");
}

//store data
info.StoreInUserVariable(sender, v_applyToVariableName);

}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor));

RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_InfoType", this, editor));

//apply to variable name
RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_applyToVariableName", this));
var applyToVariableControl = CommandControls.CreateStandardComboboxFor("v_applyToVariableName", this).AddVariableNames(editor);
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_applyToVariableName", this, new Control[] { applyToVariableControl }, editor));
RenderedControls.Add(applyToVariableControl);

return RenderedControls;
}

public override string GetDisplayValue()
{
return $"{base.GetDisplayValue()} [Get '{v_InfoType}' and apply to '{v_applyToVariableName}', Instance Name: '{v_InstanceName}']";
}
}
}
1 change: 1 addition & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("SeleniumBrowserElementActionCommand", taskt.Properties.Resources.command_web);
uiImages.Add("SeleniumBrowserExecuteScriptCommand", taskt.Properties.Resources.command_script);
uiImages.Add("SeleniumBrowserSwitchWindowCommand", taskt.Properties.Resources.command_window);
uiImages.Add("SeleniumBrowserInfoCommand", taskt.Properties.Resources.command_web);
uiImages.Add("SMTPSendEmailCommand", taskt.Properties.Resources.command_smtp);
uiImages.Add("ErrorHandlingCommand", taskt.Properties.Resources.command_error);
uiImages.Add("StringSubstringCommand", taskt.Properties.Resources.command_string);
Expand Down
1 change: 1 addition & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<Compile Include="Core\Automation\Commands\IEBrowserCloseCommand.cs" />
<Compile Include="Core\Automation\Commands\SeleniumBrowserCloseCommand.cs" />
<Compile Include="Core\Automation\Commands\IEBrowserCreateCommand.cs" />
<Compile Include="Core\Automation\Commands\SeleniumBrowserInfoCommand.cs" />
<Compile Include="Core\Automation\Commands\SeleniumBrowserSwitchWindowCommand.cs" />
<Compile Include="Core\Automation\Commands\SeleniumBrowserCreateCommand.cs" />
<Compile Include="Core\Automation\Commands\MoveWindowCommand.cs" />
Expand Down

0 comments on commit 2fe9cb8

Please sign in to comment.