Skip to content

Commit

Permalink
Enable & Disable a Attribute Control via FormJS + Load a WebResource
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelRodriguez8008 committed Nov 6, 2019
1 parent aaa0470 commit a08fb39
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Microsoft.Dynamics365.UIAutomation.Api.UCI/Elements/FormJS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public FormJS(WebClient client)
}

public BrowserCommandResult<TResult> ExecuteJS<T, TResult>(string commandName, string code, Func<T, TResult> converter) => _page.ExecuteJS(commandName, code, converter);
public bool ExecuteJS(string code, params object[] args) => _page.ExecuteJS( code, args);
public bool ExecuteJS(string commandName, string code, params object[] args) => _page.ExecuteJS(commandName, code, args);
public BrowserCommandResult<T> ExecuteJS<T>(string commandName, string code) => _page.ExecuteJS<T>(commandName, code);

Expand All @@ -26,5 +27,8 @@ public FormJS(WebClient client)
public BrowserCommandResult<bool> IsControlVisible(string attributte) => _page.IsControlVisible(attributte);
public BrowserCommandResult<bool> IsDirty(string attributte) => _page.IsDirty(attributte);
public BrowserCommandResult<FormJSPage.RequiredLevel> GetRequiredLevel(string attributte) => _page.GetRequiredLevel(attributte);
public bool Enable(string attributte) => _page.Enable(attributte);
public bool Disable(string attributte) => _page.Disable(attributte);
public bool LoadWebResource(string webResourceName, bool async = true) => _page.LoadWebResource(webResourceName, async);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
</Target>
<Import Project="..\packages\Selenium.Firefox.WebDriver.0.24.0\build\Selenium.Firefox.WebDriver.targets" Condition="Exists('..\packages\Selenium.Firefox.WebDriver.0.24.0\build\Selenium.Firefox.WebDriver.targets')" />
<Import Project="..\packages\Selenium.Chrome.WebDriver.76.0.0\build\Selenium.Chrome.WebDriver.targets" Condition="Exists('..\packages\Selenium.Chrome.WebDriver.76.0.0\build\Selenium.Chrome.WebDriver.targets')" />
<PropertyGroup>
<PostBuildEvent>copy C:\~Projects\contributions\EasyRepro\Microsoft.Dynamics365.UIAutomation.Api.UCI\bin\Debug\Microsoft.Dynamics365.UIAutomation.* C:\~Projects\RailCargo\Tests\ORBIS.Rcg.UI.Tests\libs /Y</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.19295.1032")]
[assembly: AssemblyFileVersion("1.0.19295.1032")]
[assembly: AssemblyVersion("1.0.19298.1349")]
[assembly: AssemblyFileVersion("1.0.19298.1349")]
46 changes: 45 additions & 1 deletion Microsoft.Dynamics365.UIAutomation.Api/Pages/FormJS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public BrowserCommandResult<TResult> ExecuteJS<T, TResult>(string commandName, s
=> _worker.ExecuteJS(commandName, code, converter);
public bool ExecuteJS(string commandName, string code, params object[] args)
=> _worker.ExecuteJS(commandName, code, args);

public bool ExecuteJS(string code, params object[] args)
=> ExecuteJS("Execute JS via FormJS", code, args);
public BrowserCommandResult<T> ExecuteJS<T>(string commandName, string code)
=> ExecuteJS<T, T>(commandName, code, result => result);

Expand Down Expand Up @@ -93,5 +94,48 @@ public BrowserCommandResult<RequiredLevel> GetRequiredLevel(string attributte)
});
}

public bool Disable(string attributte) => Enable(attributte, false);
public bool Enable(string attributte, bool value = true)
{
var commandName = $"Enable Attribute via Form JS: {attributte}";
string code = $"return Xrm.Page.getControl('{attributte}').setDisabled({(value? "false" : "true")});";

return ExecuteJS(commandName, code);
}

public bool LoadWebResource(string webResourceName, bool async = true)
{
string strAsync = async ? "true" : "false";
var commandName = $"Load Web Resource: {webResourceName}";

// credit: Ben John => How to load Javascript from a webresource
// https://community.dynamics.com/365/b/leichtbewoelkt/posts/how-to-load-javascript-from-a-webresource
string code = $@"(function() {{
let req = new XMLHttpRequest();
req.open('GET', Xrm.Page.context.getClientUrl() + '/api/data/v8.0/webresourceset?' +
""$select=content&$filter=name eq '{webResourceName}'"", {strAsync});
req.setRequestHeader('OData-Version', '4.0');
req.setRequestHeader('OData-MaxVersion', '4.0');
req.setRequestHeader('Accept', 'application/json');
req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
req.onreadystatechange = function () {{
if (this.readyState === 4) {{
req.onreadystatechange = null;
if (this.status === 200) {{
var result = (JSON.parse(this.response)).value[0].content;
var script = atob(result);
window.eval(script);
return true;
}}
else
console.error(this.statusText);
}}
return false;
}};
req.send();
}})();";

return ExecuteJS(commandName, code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dfe2c141-f1aa-4d4b-8df8-0fb93023cf45")]
[assembly: AssemblyVersion("8.2.19295.0952")]
[assembly: AssemblyFileVersion("8.2.19295.0952")]
[assembly: AssemblyVersion("8.2.19298.1349")]
[assembly: AssemblyFileVersion("8.2.19298.1349")]

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c9748803-f3cb-4531-b313-bc24d4d0bf0c")]
[assembly: AssemblyVersion("8.2.19294.1302")]
[assembly: AssemblyFileVersion("8.2.19294.1302")]
[assembly: AssemblyVersion("8.2.19298.1349")]
[assembly: AssemblyFileVersion("8.2.19298.1349")]

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a075b87e-dca5-4a2a-909b-932e2f5f98b4")]
[assembly: AssemblyVersion("8.2.19295.1032")]
[assembly: AssemblyFileVersion("8.2.19295.1032")]
[assembly: AssemblyVersion("8.2.19298.1349")]
[assembly: AssemblyFileVersion("8.2.19298.1349")]

0 comments on commit a08fb39

Please sign in to comment.