forked from saucepleez/taskt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Browser Info command to retrieve additional selenium instance data
- Loading branch information
1 parent
447da62
commit 2fe9cb8
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
taskt/Core/Automation/Commands/SeleniumBrowserInfoCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}']"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters