-
Notifications
You must be signed in to change notification settings - Fork 15
Tutorial 12
PhuocLe edited this page Aug 27, 2018
·
9 revisions
- Create UI Automation Test
- Finish Tutorial 1: Plugin
- Finish Tutorial 2: Unit Test Plugin
- Finish Tutorial 3: WebResource
- Finish Tutorial 4: Unit Test WebResource
- Finish Tutorial 5: Custom Workflow
- Finish Tutorial 6: WebApiClient
- Finish Tutorial 7: Custom Action
- Finish Tutorial 8: Plugin and Unit Test Plugin
- Finish Tutorial 9: Qualify Lead
- Finish Tutorial 10: Unit Test Custom Workflow
- Finish Tutorial 11: Unit Test Custom Action
- Add
New Project
08. C# Ui Test Project
to your solution- A popup form
Add new Test Project
opened - Click button
><
to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKit
loaded all entities and bind to dropdownProject Name
- Keep the text box
Project Name
empty - Select
9.0.2.4
in theCrm Version
PL.DynamicsCrm.DevKit
get allMicrosoft.CrmSdk.CoreAssemblies
version fromNuGet
- Select
4.5.2
in the.Net version
- Click
OK
-
PL.DynamicsCrm.DevKit
created test project name:Paz.LuckeyMonkey.UiTest
- A popup form
- Rebuild solution to restore
NuGet
packages - Add
New Item
06. C# Test Ui Class
toPaz.LuckeyMonkey.UiTest
project- A popup form
Add new Ui Test CLass
opened - Enter
QualifyLead
in theClass Name
- Click
OK
-
PL.DynamicsCrm.DevKit
created test class:QualifyLeadTest
- A popup form
- Open file
App.config
and update keyOnlineCrmUrl
to your current crm - Edit
QualifyLeadTest.cs
[TestClass]
public class QualifyLeadTest
{
private readonly SecureString _username = System.Configuration.ConfigurationManager.AppSettings["Username"].ToSecureString();
private readonly SecureString _password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToSecureString();
private readonly Uri _xrmUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OnlineCrmUrl"].ToString());
[TestMethod]
public void UiQualifyLeadTest()
{
using (var chrome = new Browser(TestSettings.Options))
{
var key = $"key{new Random().Next().ToString("000000")}";
chrome.LoginPage.Login(_xrmUri, _username, _password);
chrome.Navigation.OpenSubArea("Sales", "Leads");
chrome.Grid.SwitchView("All Leads");
chrome.CommandBar.ClickCommand("New");
chrome.Entity.SetValue("subject", key);
var fields = new List<Field>
{
new Field() {Id = "firstname", Value = key},
new Field() {Id = "lastname", Value = key}
};
chrome.Entity.SetValue(new CompositeControl() { Id = "fullname", Fields = fields });
chrome.Entity.SetValue("paz_field1", key);
chrome.Entity.SetValue("companyname", key);
chrome.CommandBar.ClickCommand("Save & Close");
chrome.Grid.SwitchView("Open Leads");
chrome.Grid.SelectRecord(0);
chrome.CommandBar.ClickCommand("Edit");
chrome.ThinkTime(1000);
chrome.CommandBar.ClickCommand("Qualify");
chrome.ThinkTime(10000);
//now check real data ??
//check Account
var fetchData = new
{
name = key
};
var fetchXml = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='accountid'/>
<filter type='and'>
<condition attribute='name' operator='eq' value='{fetchData.name}'/>
</filter>
</entity>
</fetch>
";
var accounts = AppSettings.CrmService.RetrieveAll<Account>(fetchXml);
Assert.AreEqual(1, accounts.Count);
var account = accounts[0];
var accountId = account.Id;
//check lead
var fetchData2 = new
{
subject = key
};
var fetchXml2 = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='lead'>
<attribute name='leadid'/>
<attribute name='subject'/>
<attribute name='statecode'/>
<filter type='and'>
<condition attribute='subject' operator='eq' value='{fetchData2.subject}'/>
</filter>
</entity>
</fetch>
";
var leads = AppSettings.CrmService.RetrieveAll<Lead>(fetchXml2);
Assert.AreEqual(1, leads.Count);
var lead = leads[0];
Assert.AreEqual(key.ToUpper(), lead.Subject, false);
Assert.AreEqual(Shared.Entities.LeadOptionSets.StateCode.Qualified, lead.StateCode.Value);
var leadId = lead.Id;
//check contact
var fetchData3 = new
{
firstname = key,
lastname = key
};
var fetchXml3 = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='contact'>
<attribute name='contactid'/>
<filter type='and'>
<condition attribute='firstname' operator='eq' value='{fetchData3.firstname}'/>
<condition attribute='lastname' operator='eq' value='{fetchData3.lastname}'/>
</filter>
</entity>
</fetch>
";
var contacts = AppSettings.CrmService.RetrieveAll<Contact>(fetchXml3);
Assert.AreEqual(1, contacts.Count);
var contact = contacts[0];
var contactId = contact.Id;
//check email
var fetchData4 = new
{
regardingobjectid = leadId
};
var fetchXml4 = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='email'>
<attribute name='activityid'/>
<filter type='and'>
<condition attribute='regardingobjectid' operator='eq' value='{fetchData4.regardingobjectid}'/>
</filter>
</entity>
</fetch>
";
var emails = AppSettings.CrmService.RetrieveAll<Email>(fetchXml4);
Assert.AreEqual(2, emails.Count);
//Delete data
AppSettings.CrmService.Delete(Email.EntityLogicalName, emails[1].Id);
AppSettings.CrmService.Delete(Email.EntityLogicalName, emails[0].Id);
AppSettings.CrmService.Delete(Contact.EntityLogicalName, contactId);
AppSettings.CrmService.Delete(Account.EntityLogicalName, accountId);
AppSettings.CrmService.Delete(Lead.EntityLogicalName, leadId);
//Success delete data
Assert.IsTrue(true);
}
}
}
NOTED
You should add 01. C# Late Bound Class
class: Contact
to Entities
folder of Paz.LuckeyMonkey.Shared
project
- Run
Unit Test
andpassed
- Check-in all files to your source control
- You finished this tutorial
This tutorial, you know howto
- Add
08. C# Ui Test Project
- Add
06. C# Test Ui Class
- Edit
App.config