protected override UserContext CreateUserContext(TestContext testContext) { var userId = GetTestUserId(testContext); var userTenantId = GetUserTenantId(userId); var userName = GetTenantUserName(userId); var userContext = new UserContext(userTenantId, Company, AuthenticationScheme.UserNamePassword, userName, DefaultNAVPassword); return userContext; }
public static void ClosePage(TestContext testContext, UserContext context, ClientLogicalForm form) { if (form.State == ClientLogicalFormState.Open) { using (new TestTransaction(testContext, String.Format("ClosePage{0}", UserContext.GetActualPageNo(form)))) { context.InvokeInteraction(new CloseFormInteraction(form)); } } }
/// <summary> /// Open a page run an action and close the page /// </summary> /// <param name="testContext">current Test Context</param> /// <param name="context">current user Context</param> /// <param name="pageId">page to open</param> /// <param name="formAction">action to run</param> public static void RunPageAction(TestContext testContext, UserContext context, int pageId, Action<ClientLogicalForm> formAction = null) { var form = OpenPage(testContext, context, pageId); if (formAction != null) { formAction(form); } ClosePage(testContext, context, form); }
public static ClientLogicalForm OpenPage(TestContext testContext, UserContext context, int pageId) { ClientLogicalForm form; using (new TestTransaction(testContext, String.Format("OpenPage{0}", pageId))) { form = context.OpenForm(pageId.ToString(CultureInfo.InvariantCulture)); context.EnsurePage(pageId, form); } DelayTiming.SleepDelay(DelayTiming.OpenFormDelay); return form; }
public static void ApplyColumnFilter( TestContext testContext, UserContext userContext, ClientRepeaterColumnControl column, string value) { using (new TestTransaction(testContext, "FilterBy" + column.Caption)) { var filterForm = column.Action("Filter...").InvokeCatchDialog(); var filterControl = filterForm.Control(column.Caption); filterControl.SaveValue(value); userContext.InvokeInteraction( new InvokeActionInteraction( filterForm.Action("OK"))); } }
private static void CloseSession(UserContext userContext, TestContext testContext) { try { using (new TestTransaction(testContext, "CloseSession")) { userContext.CloseSession(); } } catch (Exception exception) { testContext.WriteLine("Error occurred on CloseSession {0}", exception.Message); } }
public static string SelectRandomRecordFromLookup( TestContext testContext, UserContext context, ClientLogicalControl control, string keyFieldCaption) { var form = control.InvokeCatchLookup(); if (form == null) { throw new InvalidOperationException("No Lookup Form found"); } try { var randomKey = SelectRandomRecord(form, keyFieldCaption); testContext.WriteLine( "Selected Random Record from Lookup:{0} Key:{1} Value:{2}", control.Caption, keyFieldCaption, randomKey); return randomKey; } finally { ClosePage(testContext, context, form); } }
public static string SelectRandomRecordFromListPage( TestContext testContext, UserContext context, int pageId, string keyFieldCaption) { string randomKey = null; RunPageAction(testContext, context, pageId, form => { randomKey = SelectRandomRecord(form, keyFieldCaption); testContext.WriteLine( "Selected Random Record from Page:{0} Key:{1} Value:{2}", pageId, keyFieldCaption, randomKey); }); return randomKey; }
/// <summary> /// Save the specified value with entry delay and ignore any warning dialogs /// </summary> /// <param name="context">the current test contest</param> /// <param name="userContext">the user context</param> /// <param name="control">the control to be updated</param> /// <param name="value">the value</param> /// <param name="ignoreAction">the name of the action, default is Yes</param> public static void SaveValueAndIgnoreWarning(TestContext context, UserContext userContext, ClientLogicalControl control, string value, string ignoreAction = "Yes") { var dialog = userContext.CatchDialog(() => SaveValueWithDelay(control, value)); if (dialog != null) { try { var action = dialog.Action(ignoreAction); if (action != null) { action.Invoke(); context.WriteLine("Dialog Caption: {0} Message: {1} was ignored with Action: {2} ", dialog.Caption, dialog.FindMessage(), ignoreAction); } } catch (InvalidOperationException) { context.WriteLine("Dialog Caption: {0} Message: {1} Action: {2} was not found.", dialog.Caption, dialog.FindMessage(), ignoreAction); throw; } } }
private void PostPurchaseInvoice( UserContext userContext, ClientLogicalForm purchaseInvoicePage) { ClientLogicalForm openPostedInvoiceDialog; using (new TestTransaction(TestContext, "Post")) { var postConfirmationDialog = purchaseInvoicePage.Action("Post") .InvokeCatchDialog(); if (postConfirmationDialog == null) { userContext.ValidateForm(purchaseInvoicePage); Assert.Fail("Confirm Post dialog not found"); } openPostedInvoiceDialog = postConfirmationDialog.Action("Yes") .InvokeCatchDialog(); } if (openPostedInvoiceDialog == null) { Assert.Fail("Open Posted Invoice dialog not found"); } ClientLogicalForm postedPurchaseInvoicePage; using (new TestTransaction(TestContext, "OpenPostedPurchaseInvoice")) { postedPurchaseInvoicePage = userContext.EnsurePage( PostedPurchaseInvoiceCard, openPostedInvoiceDialog.Action("Yes").InvokeCatchForm()); } TestContext.WriteLine( "Posted Purchase Invoice {0}", postedPurchaseInvoicePage.Caption); TestScenario.ClosePage( TestContext, userContext, postedPurchaseInvoicePage); }
private ClientLogicalForm CreateNewPurchaseInvoice(UserContext userContext) { // Invoke using the Purchase Invoice action on Role Center and catch the new page var newPurchaseInvoicePage = userContext.EnsurePage( MiniPurchaseInvoiceCard, userContext.RoleCenterPage.Action("Purchase Invoice") .InvokeCatchForm()); var vendorName = TestScenario.SelectRandomRecordFromListPage( TestContext, userContext, MiniVendorList, "Name"); TestScenario.SaveValueAndIgnoreWarning( TestContext, userContext, newPurchaseInvoicePage.Control("Vendor Name"), vendorName); var vendorInvoiceNo = SafeRandom.GetRandomNext(100000, 999999); TestScenario.SaveValueWithDelay( newPurchaseInvoicePage.Control("Vendor Invoice No."), vendorInvoiceNo); // Add a random number of lines between 2 and 15 var noOfLines = SafeRandom.GetRandomNext(2, 15); for (var line = 0; line < noOfLines; line++) { AddPurchaseInvoiceLine(userContext, newPurchaseInvoicePage, line); } userContext.ValidateForm(newPurchaseInvoicePage); TestContext.WriteLine( "Created Purchase Invoice {0}", newPurchaseInvoicePage.Caption); return newPurchaseInvoicePage; }
private void AddPurchaseInvoiceLine( UserContext userContext, ClientLogicalForm purchaseInvoicePage, int index) { using (new TestTransaction(TestContext, "AddPurchaseInvoiceLine")) { var repeater = purchaseInvoicePage.Repeater(); var rowCount = repeater.Offset + repeater.DefaultViewport.Count; if (index >= rowCount) { // scroll to the next viewport userContext.InvokeInteraction( new ScrollRepeaterInteraction(repeater, 1)); } var rowIndex = (int) (index - repeater.Offset); var itemsLine = repeater.DefaultViewport[rowIndex]; // select random Item No. from lookup var itemNoControl = itemsLine.Control("Item No."); var itemNo = TestScenario.SelectRandomRecordFromLookup( TestContext, userContext, itemNoControl, "No."); TestScenario.SaveValueWithDelay(itemNoControl, itemNo); var qtyToOrder = SafeRandom.GetRandomNext(1, 10); TestScenario.SaveValueWithDelay(itemsLine.Control("Quantity"), qtyToOrder); } }
/// <summary> /// Return the user context to the pool /// </summary> /// <param name="testContext"></param> /// <param name="userContext"></param> public void ReturnUserContext(TestContext testContext, UserContext userContext) { if (userContext != null) { int userId = GetTestUserId(testContext); this.UserContextPool.TryAdd(userId, userContext); } }
private void PostSalesOrder(UserContext userContext, ClientLogicalForm newSalesOrderPage) { ClientLogicalForm postConfirmationDialog; using (new TestTransaction(TestContext, "Post")) { postConfirmationDialog = newSalesOrderPage.Action("Post...").InvokeCatchDialog(); } if (postConfirmationDialog == null) { userContext.ValidateForm(newSalesOrderPage); Assert.Inconclusive("Post dialog can't be found"); } using (new TestTransaction(TestContext, "ConfirmShipAndInvoice")) { ClientLogicalForm dialog = userContext.CatchDialog(postConfirmationDialog.Action("OK").Invoke); if (dialog != null) { // after confiming the post we dont expect more dialogs Assert.Fail("Unexpected Dialog on Post - Caption: {0} Message: {1}", dialog.Caption, dialog.FindMessage()); } } }
private void AddSalesOrderLine(UserContext userContext, ClientLogicalForm newSalesOrderPage, int index) { var repeater = newSalesOrderPage.Repeater(); var rowCount = repeater.Offset + repeater.DefaultViewport.Count; if (index >= rowCount) { // scroll to the next viewport userContext.InvokeInteraction(new ScrollRepeaterInteraction(repeater, 1)); } var rowIndex = (int)(index - repeater.Offset); var itemsLine = repeater.DefaultViewport[rowIndex]; // Activate Type field itemsLine.Control("Type").Activate(); // set Type = Item TestScenario.SaveValueWithDelay(itemsLine.Control("Type"), "Item"); // Set Item No. from random lookup var itemNoControl = itemsLine.Control("No."); var itemNo = TestScenario.SelectRandomRecordFromLookup(TestContext, userContext, itemNoControl, "No."); TestScenario.SaveValueWithDelay(itemNoControl, itemNo); var qtyToOrder = SafeRandom.GetRandomNext(1, 10).ToString(CultureInfo.InvariantCulture); TestScenario.SaveValueAndIgnoreWarning(TestContext, userContext, itemsLine.Control("Quantity"), qtyToOrder); TestScenario.SaveValueAndIgnoreWarning(TestContext, userContext, itemsLine.Control("Qty. to Ship"), qtyToOrder, "OK"); // Look at the line for 1 seconds. DelayTiming.SleepDelay(DelayTiming.ThinkDelay); }
public void RunCreateAndPostSalesOrder(UserContext userContext) { // Invoke using the new sales order action on Role Center var newSalesOrderPage = userContext.EnsurePage(SalesOrderPageId, userContext.RoleCenterPage.Action("Sales Order").InvokeCatchForm()); // Start in the No. field newSalesOrderPage.Control("No.").Activate(); // Navigate to Sell-to Customer No. field in order to create record var sellToCustControl = newSalesOrderPage.Control("Sell-to Customer No."); sellToCustControl.Activate(); // select a random customer from Sell-to Customer No. lookup var custNo = TestScenario.SelectRandomRecordFromLookup(TestContext, userContext, sellToCustControl, "No."); // Set Sell-to Customer No. to a Random Customer and ignore any credit warning TestScenario.SaveValueAndIgnoreWarning(TestContext, userContext, sellToCustControl, custNo); TestScenario.SaveValueWithDelay(newSalesOrderPage.Control("External Document No."), custNo); var newSalesOrderNo = newSalesOrderPage.Control("No.").StringValue; userContext.ValidateForm(newSalesOrderPage); TestContext.WriteLine("Created Sales Order No. {0} for Cust No. {1}", newSalesOrderNo, custNo); // Add a random number of lines between 2 and 25 var noOfLines = SafeRandom.GetRandomNext(2, 25); for (var line = 0; line < noOfLines; line++) { AddSalesOrderLine(userContext, newSalesOrderPage, line); } // Check Validation errors userContext.ValidateForm(newSalesOrderPage); // Post the order PostSalesOrder(userContext, newSalesOrderPage); // Close the page TestScenario.ClosePage(TestContext, userContext, newSalesOrderPage); }