Ejemplo n.º 1
0
        /// <summary>
        /// Perform actual invokation on all objects
        /// </summary>
        public TBinding Invoke <TBinding>(string triggerName, TBinding data) where TBinding : IdentifiedData
        {
            lock (this.m_lock)
            {
                using (AuthenticationContext.EnterSystemContext())
                {
                    if (data == default(TBinding))
                    {
                        return(data);
                    }

                    var callList = this.GetCallList(data.GetType(), triggerName);
                    callList = callList.Union(this.GetCallList <TBinding>(triggerName), this.m_javascriptComparer).ToList();
                    var retVal = data;

                    if (callList.Count() > 0)
                    {
                        dynamic viewModel = JavascriptUtils.ToViewModel(retVal);
                        foreach (var c in callList)
                        {
                            try
                            {
                                // There is a guard so let's execute it
                                if (c.Guard == null || QueryExpressionParser.BuildLinqExpression <TBinding>(c.Guard).Compile()(data))
                                {
                                    viewModel = c.Callback.DynamicInvoke(viewModel);
                                }
                            }
                            catch (JavaScriptException e)
                            {
                                this.m_tracer.TraceError("JS ERROR: Error running {0} for {1} @ {2}:{3} \r\n Javascript Stack: {4} \r\n C# Stack: {5}",
                                                         triggerName, data, e.Location.Source, e.LineNumber, e.CallStack, e);
                                throw new JsBusinessRuleException($"Error running business rule {c.Id} - {triggerName} for {data}", e);
                            }
                            catch (TargetInvocationException e) when(e.InnerException is JavaScriptException je)
                            {
                                this.m_tracer.TraceError("JS ERROR: Error running {0} for {1} @ {2}:{3} \r\n Javascript Stack: {4} \r\n C# Stack: {5}",
                                                         triggerName, data, je.Location.Source, je.LineNumber, je.CallStack, e);
                                throw new JsBusinessRuleException($"Error running business rule {c.Id} - {triggerName} for {data}", je);
                            }
                            catch (Exception e)
                            {
                                this.m_tracer.TraceError("Error running {0} for {1} : {2}", triggerName, data, e);
                                throw new JsBusinessRuleException($"Error running business rule {c.Id} - {triggerName} for {data}", e);
                            }
                        }

                        retVal = (TBinding)JavascriptUtils.ToModel(viewModel).CopyAnnotations(retVal);
                    }

                    return(retVal);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Validate the data object if validation is available
 /// </summary>
 public List <DetectedIssue> Validate <TBinding>(TBinding data) where TBinding : IdentifiedData
 {
     lock (this.m_lock)
     {
         using (AuthenticationContext.EnterSystemContext())
         {
             var callList = this.GetCallList(data.GetType(), "Validate").Union(this.GetCallList <TBinding>("Validate"), this.m_javascriptComparer).Distinct();
             var retVal   = new List <DetectedIssue>();
             var vmData   = JavascriptUtils.ToViewModel(data);
             foreach (var c in callList)
             {
                 try
                 {
                     object[] issues = null;
                     issues = c.Callback.DynamicInvoke(vmData) as object[];
                     retVal.AddRange(issues.Cast <IDictionary <String, Object> >().Select(o => new DetectedIssue()
                     {
                         Text     = o.ContainsKey("text") ? o["text"]?.ToString() : null,
                         Priority = o.ContainsKey("priority") ? (DetectedIssuePriorityType)(int)(double)o["priority"] : DetectedIssuePriorityType.Information,
                         TypeKey  = o.ContainsKey("type") ? Guid.Parse(o["type"].ToString()) : DetectedIssueKeys.BusinessRuleViolationIssue
                     }));
                 }
                 catch (JavaScriptException e)
                 {
                     this.m_tracer.TraceError("Error validating {0} (rule: {1}) : {2}", data, c.Id, e);
                     return(new List <DetectedIssue>()
                     {
                         new DetectedIssue()
                         {
                             Priority = DetectedIssuePriorityType.Error,
                             Text = $"Error validating {data} (rule: {c.Id}) - {e.Message} @ {e.LineNumber}"
                         }
                     });
                 }
                 catch (Exception e)
                 {
                     this.m_tracer.TraceError("Error validating {0} (rule: {1}) : {2}", data, c.Id, e);
                     return(new List <DetectedIssue>()
                     {
                         new DetectedIssue()
                         {
                             Priority = DetectedIssuePriorityType.Error,
                             Text = $"Error validating {data} (rule: {c.Id}) - {e.Message}"
                         }
                     });
                 }
             }
             return(retVal);
         }
     }
 }
        /// <summary>
        /// Fills the required fields on the AMA Group Learning Page
        /// </summary>
        ///
        public void FillOutAMAActivityForm2()
        {
            //generate the data to fill out the data
            DateTime dt            = DateTime.Now;
            int      currentDay    = dt.Day;
            int      currentMonth  = dt.Month;
            int      currentYear   = dt.Year;
            int      currentHour   = dt.Hour;
            int      currentMinute = dt.Minute;
            int      currentSecond = dt.Second;

            //create a string for the program title
            String ProgramTitle = "TestRun_" + currentMonth + "_" + currentDay + "_" + currentYear + "-" + currentHour + ":" + currentMinute + ":" + currentSecond;


            //These lines fill out the
            //text fields in the AMA Group Learning Activity Form

            ProgramTitleAMAGLTxt.SendKeys(ProgramTitle);
            ProvinceSelectorAMAGLDrpDn.SelectByIndex(1);
            ProvinceSelectorAMAGLDrpDn.SelectByText("Alberta (AB)");
            CityAMAGLTxt.SendKeys("Test City");
            PlanningOrganizationAMAGLTxt.SendKeys("Test");
            string date = DateTime.Today.AddDays(-1).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);  //generate a date value for the activity forms

            ElemSet.ScrollToElement(Browser, ActivityStartDateAMAGLTxt);
            ActivityStartDateAMAGLTxt.SendKeys(date);
            ActivityCompletionDateAMAGLTxt.SendKeys(date);
            CreditsClaimedAMAGLTxt.SendKeys("1");

            //Select out the group radio buttons
            ElemSet.ClickAfterScroll(Browser, ChangedImprovedAMAGLRdo);
            ElemSet.ClickAfterScroll(Browser, LearnedNewAMAGLRdo);
            ElemSet.ClickAfterScroll(Browser, LearnedMoreAMAGLRdo);
            ElemSet.ClickAfterScroll(Browser, DissatisfiedAMAGLRdo);
            ElemSet.ClickAfterScroll(Browser, BiasedAMAGLRdo);
            ElemSet.ClickAfterScroll(Browser, ConfirmedAMAGLRdo);



            // MIKE: I would name these elements with a little more detail. It took me, a new person, a little bit of time to figure out what radio button was for each variable
            // MIKE: Always start with the beginning text when naming elements. For example for this radio button, name it "ThisExperienceConfirmedRdo" instead of just "Confirmed"

            // For some reason, whenever we use Selenium's built in click method here, it triggers the application to add more than
            // 1 credit for the activity/user (We entered "1" into the CreditsClaimed text box above, so only 1 credit should get
            // added for the user). I added a workaround to use the javascript version of a click, and this
            // works (only adds the specified amount of credits) For more info,
            // see https://stackoverflow.com/questions/24571048/selenium-webelement-click-vs-javascript-click-event
            JavascriptUtils.Click(Browser, SubmitButton);
            SubmitButton.SendKeys(Keys.Tab);
        }
        /// <summary>
        /// Fills the required fields on the AMA Self Learning Page
        /// </summary>
        ///
        public void FillOutAMAActivityForm1(int creditValue)
        {
            //generate the data to fill out the data
            DateTime dt            = DateTime.Now;
            int      currentDay    = dt.Day;
            int      currentMonth  = dt.Month;
            int      currentYear   = dt.Year;
            int      currentHour   = dt.Hour;
            int      currentMinute = dt.Minute;
            int      currentSecond = dt.Second;

            //create a string for the program title
            String ProgramTitle = "TestRun_" + currentMonth + "_" + currentDay + "_" + currentYear + "-" + currentHour + ":" + currentMinute + ":" + currentSecond;


            //These lines fill out the
            //text fields in the AMA Self Learning Activity Form

            ProgramTitleAMASLTxt.SendKeys(ProgramTitle);
            ProvinceSelectorAMASLDrpDn.SelectByIndex(1);
            ProvinceSelectorAMASLDrpDn.SelectByText("Alberta (AB)");
            CityAMASLTxt.SendKeys("Test City");
            PlanningOrganizationAMASLTxt.SendKeys("Test");
            string date = DateTime.Today.AddDays(-1).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);  //Generate a date to use later in the form

            ElemSet.ScrollToElement(Browser, ActivityStartDateAMASLTxt);
            ActivityStartDateAMASLTxt.SendKeys(date);
            ActivityCompletionDateAMASLTxt.SendKeys(date);
            CreditsClaimedAMASLTxt.SendKeys("" + creditValue);



            //clicking on the radio buttons
            //at the end of the form
            ElemSet.ClickAfterScroll(Browser, ChangedImprovedAMASLRdo);
            ElemSet.ClickAfterScroll(Browser, LearnedNewAMASLRdo);
            ElemSet.ClickAfterScroll(Browser, LearnedMoreAMASLRdo);
            ElemSet.ClickAfterScroll(Browser, DissatisfiedAMASLRdo);
            ElemSet.ClickAfterScroll(Browser, BiasedAMASLRdo);
            ElemSet.ClickAfterScroll(Browser, ConfirmedAMASLRdo);

            // For some reason, whenever we use Selenium's built in click method here, it triggers the application to add more than
            // 1 credit for the activity/user (We entered "1" into the CreditsClaimed text box above, so only 1 credit should get
            // added for the user). I added a workaround to use the javascript version of a click, and this
            // works (only adds the specified amount of credits) For more info,
            // see https://stackoverflow.com/questions/24571048/selenium-webelement-click-vs-javascript-click-event
            JavascriptUtils.Click(Browser, SubmitButton);
            SubmitButton.SendKeys(Keys.Tab);

            Thread.Sleep(20000);     // MIKE: Definitely add wait criteria here. I see that a popup appears, we can wait on an element in this popup
        }
        /// <summary>
        /// Gets the specified data from the underlying data-store
        /// </summary>
        public object Obsolete(String type, Guid id)
        {
            try
            {
                Type dataType = this.m_binder.BindToType(null, type);

                var idp         = typeof(IRepositoryService <>).MakeGenericType(dataType);
                var idpInstance = ApplicationServiceContext.Current.GetService(idp) as IRepositoryService;
                if (idpInstance == null)
                {
                    throw new KeyNotFoundException($"The repository service for {type} was not found. Ensure an IRepositoryService<{type}> is registered");
                }

                return(JavascriptUtils.ToViewModel(idpInstance.Obsolete(id)));
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error obsoleting BRE object: {0}/{1} - {2}", type, id, e);
                throw new Exception($"Error obsoleting BRE object: {type}/{id}", e);
            }
        }
        /// <summary>
        /// Execute bundle rules
        /// </summary>
        public Object ExecuteBundleRules(String trigger, Object bundle)
        {
            try
            {
                IDictionary <String, Object> bdl = bundle as IDictionary <String, Object>;

                object rawItems = null;
                if (!bdl.TryGetValue("resource", out rawItems))
                {
                    this.m_tracer.TraceVerbose("Bundle contains no items: {0}", JavascriptUtils.ProduceLiteral(bdl));
                    return(bundle);
                }

                Object[] itms = rawItems as object[];

                for (int i = 0; i < itms.Length; i++)
                {
                    try
                    {
                        itms[i] = this.m_owner.InvokeRaw(trigger, itms[i]);
                    }
                    catch (Exception)
                    {
                        //if (System.Diagnostics.Debugger.IsAttached)
                        throw;
                        //else
                        //    Tracer.GetTracer(typeof(BusinessRulesBridge)).TraceError("Error applying rule for {0}: {1}", itms[i], e);
                    }
                }

                //bdl.Add("resource", itms);
                return(bdl);
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error executing bundle rules: {0}", e);
                throw;
            }
        }
        /// <summary>
        /// Finds the specified data
        /// </summary>
        public object Find(String type, String query)
        {
            try
            {
                Type dataType = this.m_binder.BindToType(null, type);
                if (dataType == null)
                {
                    throw new InvalidOperationException($"Cannot find type information for {type}");
                }

                var idp         = typeof(IRepositoryService <>).MakeGenericType(dataType);
                var idpInstance = ApplicationServiceContext.Current.GetService(idp) as IRepositoryService;
                if (idpInstance == null)
                {
                    throw new KeyNotFoundException($"The repository service for {type} was not found. Ensure an IRepositoryService<{type}> is registered");
                }

                var expr    = QueryExpressionParser.BuildLinqExpression(dataType, NameValueCollection.ParseQueryString(query));
                var results = idpInstance.Find(expr).OfType <IdentifiedData>();
                return(JavascriptUtils.ToViewModel(new Bundle()
                {
                    Item = results.ToList(),
                    TotalResults = results.Count()
                }));
            }
            catch (TargetInvocationException e)
            {
                this.m_tracer.TraceError("Persistence searching from BRE: {0}?{1} - {2}", type, query, e.InnerException);
                throw new Exception($"Persistence searching from BRE : {type}?{query}", e.InnerException);
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error searching from BRE: {0}?{1} - {2}", type, query, e);
                throw new Exception($"Error searching from BRE: {type}?{query}", e);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Clicks the user-specified element, and then waits for a window to close or open, or a page to load, depending on the element that was clicked
        /// </summary>
        /// <param name="buttonOrLinkElem">The element to click on</param>
        public dynamic ClickAndWait(IWebElement buttonOrLinkElem)
        {
            // Error handler to make sure that the button that the tester passed in the parameter is actually on the page
            if (Browser.Exists(Bys.ActivityMainPage.PubDetailsTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == PubDetailsTab.GetAttribute("outerHTML"))
                {
                    //   buttonOrLinkElem.Click();
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);

                    this.WaitUntil(Criteria.ActivityMainPage.PubDetailsTabAvailCatTblVisible);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.DetailsTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == DetailsTab.GetAttribute("outerHTML"))
                {
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    this.WaitUntil(Criteria.ActivityMainPage.PageReady);
                    return(null);
                }
            }


            if (Browser.Exists(Bys.ActivityMainPage.PubDetailsTabAvailCatSearchBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == PubDetailsTabAvailCatSearchBtn.GetAttribute("outerHTML"))
                {
                    buttonOrLinkElem.Click();
                    this.WaitUntil(Criteria.ActivityMainPage.PubDetailsTabAvailCatTblSearchCatLoadElemVisible);
                    this.WaitUntil(Criteria.ActivityMainPage.PubDetailsTabAvailCatTblSearchCatLoadElemNotVisible);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.DetailsTabUnPublishBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == DetailsTabUnPublishBtn.GetAttribute("outerHTML"))
                {
                    buttonOrLinkElem.Click();
                    Browser.WaitForElement(Bys.ActivityMainPage.DetailsTabUnPublishConfirmBtn, ElementCriteria.IsVisible);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.DetailsTabUnPublishConfirmBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == DetailsTabUnPublishConfirmBtn.GetAttribute("outerHTML"))
                {
                    buttonOrLinkElem.Click();
                    Browser.WaitForElement(Bys.ActivityMainPage.DetailsTabSavebtn, ElementCriteria.IsVisible);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.DetailsTabPublishbtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == DetailsTabPublishbtn.GetAttribute("outerHTML"))
                {
                    buttonOrLinkElem.Click();
                    Browser.WaitForElement(Bys.ActivityMainPage.DetailsTabPublishConfirmbtn, ElementCriteria.IsVisible);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.DetailsTabPublishConfirmbtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == DetailsTabPublishConfirmbtn.GetAttribute("outerHTML"))
                {
                    buttonOrLinkElem.Click();
                    Browser.WaitForElement(Bys.ActivityMainPage.DetailsTabUnPublishBtn, ElementCriteria.IsVisible);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.DetailsTabSavebtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == DetailsTabSavebtn.GetAttribute("outerHTML"))
                {
                    DetailsTabSavebtn.Click();
                    // ToDo: Need to add some type of wait criteria here. A test failed in firefox once so far because a 1 second wait wasnt long enough
                    Thread.Sleep(2500);
                    return(null);
                }
            }

            if (Browser.Exists(Bys.ActivityMainPage.EditPortalFormSaveBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == EditPortalFormSaveBtn.GetAttribute("outerHTML"))
                {
                    EditPortalFormSaveBtn.Click();
                    this.WaitUntil(Criteria.ActivityMainPage.EditPortalFormCustomFeeTxtNotVisible);
                    return(null);
                }
            }

            else
            {
                throw new Exception("No button or link was found with your passed parameter. You either need to add this button to a new If statement, " +
                                    "or if the button is already added, then the page you were on did not contain the button.");
            }

            return(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Invoke raw
        /// </summary>
        public object InvokeRaw(String triggerName, Object data)
        {
            lock (this.m_lock) // Only one object can use this thread at a time
            {
                var sdata = data as IDictionary <String, Object>;
                if (sdata == null || !sdata.ContainsKey("$type"))
                {
                    return(data);
                }
                var callList = this.GetCallList(this.m_binder.BindToType("SanteDB.Core.Model, Version=1.1.0.0", sdata["$type"].ToString()), triggerName);
                var retVal   = data;

                if (callList.Any())
                {
                    foreach (var c in callList)
                    {
                        try
                        {
                            if (c.Guard == null || this.GuardEval(c.Guard, sdata))
                            {
                                data = c.Callback.DynamicInvoke(data);
                            }
                        }
                        catch (JavaScriptException e)
                        {
                            this.m_tracer.TraceError("JAVASCRIPT ERROR RUNNING {0} OBJECT :::::> {3}@{2}\r\n{1}", triggerName, JavascriptUtils.ProduceLiteral(data), e.LineNumber, e);
                            throw new DetectedIssueException(new List <DetectedIssue>()
                            {
                                new DetectedIssue()
                                {
                                    Priority = DetectedIssuePriorityType.Error,
                                    Text     = $"Error executing {triggerName} (rule id: {c.Id}) {e.Error.ToString()} @ {e.Location.Start.Line} - {e.Location.End.Line}"
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            this.m_tracer.TraceError("Error running {0} for {1} : {2}", triggerName, JavascriptUtils.ProduceLiteral(data), e);
                            throw new JsBusinessRuleException($"Error running business rule {triggerName} for {JavascriptUtils.ProduceLiteral(data)} - {e.Message}", e);
                        }
                    }
                }

                return(data);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Clicks the user-specified element and then waits for a window to close or open, or a page to load,
        /// depending on the element that was clicked
        /// </summary>
        /// <param name="buttonOrLinkElem">The element to click on</param>
        public void ClickAndWait(IWebElement buttonOrLinkElem)
        {
            // Error handler to make sure that the button that the tester passed in the parameter is actually on the page
            if (Browser.Exists(Bys.CBDLearnerPage.BackBtn))
            {
                // This is a workaround to be able to use an IF statement on an IWebElement type.
                if (buttonOrLinkElem.GetAttribute("outerHTML") == BackBtn.GetAttribute("outerHTML"))
                {
                    BackBtn.Click();
                    this.WaitForInitialize();
                    return;
                }
            }

            if (Browser.Exists(Bys.RCPPage.CBDTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == CBDTab.GetAttribute("outerHTML"))
                {
                    buttonOrLinkElem.Click();
                    this.WaitUntil(TimeSpan.FromSeconds(180), Criteria.CBDLearnerPage.PageReadyWithProgramLearningTabReady);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.AddReflectBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectBtn.GetAttribute("outerHTML"))
                {
                    // NOTE: This sometimes does not work in Firefox whenever the tooltip for one of the tabs appears. Firefox
                    // fails to click when a tooltip is covering the button. I changed this to a Javascript and it worked so far.
                    // Monitor going forwards and if the javascript click also fails, we will have to implement a workaround
                    // in the SwitchTabs method
                    // buttonOrLinkElem.Click();
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormContinueBtn);
                    //Browser.WaitForElement(Bys.CBDLearnerPage.AddReflectFormContinueBtn, ElementCriteria.IsVisible, ElementCriteria.IsEnabled);
                    this.WaitUntil(TimeSpan.FromSeconds(360), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormContinueBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormContinueBtn.GetAttribute("outerHTML"))
                {
                    AddReflectFormContinueBtn.Click();
                    WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormBrowseBtn);
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    //Browser.WaitForElement(Bys.CBDLearnerPage.AddReflectFormBrowseBtn, ElementCriteria.IsVisible);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormSubmitBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormSubmitBtn.GetAttribute("outerHTML"))
                {
                    AddReflectFormSubmitBtn.Click();
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.PageReadyWithReflectionsTabReady);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.RequestObservationBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObservationBtn.GetAttribute("outerHTML"))
                {
                    RequestObservationBtn.Click();
                    WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.RequestObsFormObsNameTxt);
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    //Browser.WaitForElement(Bys.CBDLearnerPage.RequestObsFormObsNameTxt, ElementCriteria.IsVisible, ElementCriteria.IsEnabled);
                    //Browser.WaitForElement(Bys.CBDLearnerPage.RequestObsFormSearchBtn, ElementCriteria.IsVisible, ElementCriteria.IsEnabled);
                    // Need to revisit the above 2 lines. For some reason, this needs a tiny static wait to work sometimes
                    Thread.Sleep(0400);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormSearchBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormSearchBtn.GetAttribute("outerHTML"))
                {
                    // 11/30/17: It failed today. Said "Failed to find any elements By.XPath: //tbody[@aria-label='Select Observer']". I looked on the
                    // screenshot and the radio button never got returned, even though the label beneath it said "Showing 1-1 of 1". This tells me that
                    // this is an application bug. Hopefully this fixes itself when DEV works on performance improvements. If not, and I see this again,
                    // I might have to add some more logic below to keep clicking or something else
                    // 11/05/17: For some reason, Selenium sometimes fails to click this button. So I am adding a Catch and using javascript based click
                    // event if this fails
                    // 1/25/18: Failed. The failure said that the Ok button (The button that is lcoated on the screen after clicking the Request button)
                    // could not be found. Looked at screenshot, and it showed that the Search button did not get clicked (at least that is what I think,
                    // because ALL observers showed inside the table), the Template (Part A) radio button DID get clicked, the Observer radio button
                    // did NOT get clicked, so as a result, the Request button was disabled and could not be clicked. A video would really be helpful
                    // to debug this, because I dont know why the observer table showed ALL observers (Did the search not get clicked even with the Try
                    // Catch below? Did it actually get clicked, but the application failed to filter the observers (This would be an application bug)?)
                    // Aside form those questions, the observer still showed in the table, but failed to get selected. I am adding a longer sleep here,
                    // 5 milliseconds up from 3 milliseconds. Monitor going forward

                    try
                    {
                        RequestObsFormSearchBtn.Click();
                        this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.RequestObsFormRdoBtnTbodyVisible,
                                          Criteria.CBDLearnerPage.RequestObsFormFirstRdoVisible);
                        this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                        Thread.Sleep(0500);
                    }
                    catch
                    {
                        ((IJavaScriptExecutor)Browser).ExecuteScript("arguments[0].click()", RequestObsFormSearchBtn);
                        this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.RequestObsFormRdoBtnTbodyVisible,
                                          Criteria.CBDLearnerPage.RequestObsFormFirstRdoVisible);
                        this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                        Thread.Sleep(0500);
                    }
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormRequestBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormRequestBtn.GetAttribute("outerHTML"))
                {
                    RequestObsFormRequestBtn.Click();
                    this.WaitForElement(Bys.CBDLearnerPage.RequestObsFormOkBtn, ElementCriteria.IsVisible);
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormOkBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormOkBtn.GetAttribute("outerHTML"))
                {
                    RequestObsFormOkBtn.Click();
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormContinueBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormContinueBtn.GetAttribute("outerHTML"))
                {
                    AddReflectFormContinueBtn.Click();
                    WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormBrowseBtn);
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.ViewMoreRptsLnk))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == ViewMoreRptsLnk.GetAttribute("outerHTML"))
                {
                    ViewMoreRptsLnk.Click();
                    WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.ReportsFormShowBtn);
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.ReportsFormShowBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == ReportsFormShowBtn.GetAttribute("outerHTML"))
                {
                    ReportsFormShowBtn.Click();
                    Browser.WaitForElement(Bys.CBDLearnerPage.ReportsFormEPAObservCntChrt, ElementCriteria.IsVisible, ElementCriteria.IsEnabled, ElementCriteria.HasText);
                    return;
                }
            }

            if (Browser.Exists(Bys.CBDLearnerPage.ReportsFormCloseBtn))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == ReportsFormCloseBtn.GetAttribute("outerHTML"))
                {
                    ReportsFormCloseBtn.Click();
                    this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.PageReadyWithProgramLearningTabReady);
                    return;
                }
            }

            else
            {
                throw new Exception("No button or link was found with your passed parameter. You either need to add this button to a new If statement, or " +
                                    "if the button is already added, then the page you were on did not contain the button.");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Clicks the user-specified element that exists on every page of RCP, and then waits for a window to close or open,
        /// or a page to load, depending on the element that was clicked
        /// </summary>
        /// <param name="buttonOrLinkElem">The element to click on</param>
        public dynamic ClickAndWaitBasePage(IWebElement buttonOrLinkElem)
        {
            // Error handler to make sure that the button that the tester passed in the parameter is actually on the page
            if (Browser.Exists(Bys.RCPPage.PERAFCTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == PERAFCTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    PERCredentialStaffPage page = new PERCredentialStaffPage(Browser);
                    page.WaitForInitialize();
                    return(page);
                }
            }

            if (Browser.Exists(Bys.RCPPage.MyDiplomaTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == MyDiplomaTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    DiplomaCredentialStaffPage page = new DiplomaCredentialStaffPage(Browser);
                    page.WaitForInitialize();
                    return(page);
                }
            }

            if (Browser.Exists(Bys.RCPPage.MyDashboardTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == MyDashboardTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    MyDashboardPage page = new MyDashboardPage(Browser);
                    page.WaitForInitialize();
                    return(page);
                }
            }

            if (Browser.Exists(Bys.RCPPage.MyCPDActivitiesTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == MyCPDActivitiesTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    MyCPDActivitiesListPage page = new MyCPDActivitiesListPage(Browser);
                    page.WaitForInitialize();
                    return(page);
                }
            }

            if (Browser.Exists(Bys.RCPPage.MyMOCTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == MyMOCTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    MyMOCPage page = new MyMOCPage(Browser);
                    page.WaitForInitialize();
                    return(page);
                }
            }

            if (Browser.Exists(Bys.RCPPage.MyHoldingAreaTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == MyHoldingAreaTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    MyHoldingAreaPage page = new MyHoldingAreaPage(Browser);
                    page.WaitForInitialize();
                    return(page);
                }
            }

            if (Browser.Exists(Bys.RCPPage.CBDTab))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == CBDTab.GetAttribute("outerHTML"))
                {
                    // Using javascript based click because firefox doesnt click on these tabs using Selenium based click. Might be a current geckodriver bug. Revisit
                    JavascriptUtils.Click(Browser, buttonOrLinkElem);
                    // We dont want wait criteria here, because clicking this tab can be on any role within RCP, so there can be many things to wait for
                    return(null);
                }
            }


            if (Browser.Exists(Bys.RCPPage.LogoutLnk))
            {
                if (buttonOrLinkElem.GetAttribute("outerHTML") == LogoutLnk.GetAttribute("outerHTML"))
                {
                    LogoutLnk.Click();
                    this.WaitForElement(Bys.RCPPage.LoginLnk, ElementCriteria.IsVisible);
                    return(null);
                }
            }

            else
            {
                throw new Exception("No button or link was found with your passed parameter. You either need to add this button to a new If statement, " +
                                    "or if the button is already added, then the page you were on did not contain the button.");
            }

            return(null);
        }
        /// <summary>
        /// Fills out the Self page
        /// </summary>
        ///

        public void FillOutSelfLearningForm()
        {
            //generate the data to fill out the data

            DateTime dt            = DateTime.Now;
            int      currentDay    = dt.Day;
            int      currentMonth  = dt.Month;
            int      currentYear   = dt.Year;
            int      currentHour   = dt.Hour;
            int      currentMinute = dt.Minute;
            int      currentSecond = dt.Second;


            //create a string for the program title
            String ProgramTitle = "TestRun_" + currentMonth + "_" + currentDay + "_" + currentYear + "-" + currentHour + ":" + currentMinute + ":" + currentSecond;

            Thread.Sleep(3000);//add wait criteria later
            ElemSet.ScrollToElement(Browser, ProgramTitleCertifiedSelfLearningTxt);
            ProgramTitleCertifiedSelfLearningTxt.SendKeys(ProgramTitle);


            //move down to the province selection screen

            ElemSet.ScrollToElement(Browser, CityTxtCertifiedSelfLearningTxt);


            //select alberta
            ProvinceSelectorCertifiedSelfLearningDrpDn.SelectByIndex(1);
            //Fill out the test city
            CityTxtCertifiedSelfLearningTxt.SendKeys("Test City");
            //fill out the
            PlanningOrganizationCertifiedSelfLearningTxt.SendKeys("Test");

            //generate a date for these Activity Test
            DateTime dt2                = DateTime.Today.AddDays(-1);
            String   startDateText      = dt2.Month + "/" + dt2.Day + "/" + dt2.Year;
            String   completionDateText = dt2.Month + "/" + dt2.Day + "/" + dt2.Year;


            ActivityStartDateCertifiedSelfLearningTxt.SendKeys(startDateText);
            ActivityCompletionDateCertifiedSelfLearningTxt.SendKeys(completionDateText);

            CreditsClaimedDateCertifiedSelfLearningTxt.SendKeys("1");



            ElemSet.ClickAfterScroll(Browser, ChangedImprovedCertifiedGSelfLearningRdo);
            ElemSet.ClickAfterScroll(Browser, LearnedNewCertifiedSelfLearningRdo);
            ElemSet.ClickAfterScroll(Browser, LearnedMoreCertifiedSelfLearningRdo);
            ElemSet.ClickAfterScroll(Browser, ConfirmedCertifiedSelfLearningRdo);
            ElemSet.ClickAfterScroll(Browser, BiasedCertifiedSelfLearningRdo);
            ElemSet.ClickAfterScroll(Browser, DissatisfiedCertifiedSelfLearningRdo);


            ElemSet.ScrollToElement(Browser, SubmitButton);

            // For some reason, whenever we use Selenium's built in click method here, it triggers the application to add more than
            // 1 credit for the activity/user (We entered "1" into the CreditsClaimed text box above, so only 1 credit should get
            // added for the user). I added a workaround to use the javascript version of a click, and this
            // works (only adds the specified amount of credits) For more info,
            // see https://stackoverflow.com/questions/24571048/selenium-webelement-click-vs-javascript-click-event
            JavascriptUtils.Click(Browser, SubmitButton);
            SubmitButton.SendKeys(Keys.Tab);

            Thread.Sleep(20000);
        }
        /// <summary>
        /// Fills the required fields on the enter a CPD activity page
        /// </summary>
        ///
        public void FillOutAssessmentForm()
        {
            //generate the data to fill out the data
            DateTime dt            = DateTime.Now;
            int      currentDay    = dt.Day;
            int      currentMonth  = dt.Month;
            int      currentYear   = dt.Year;
            int      currentHour   = dt.Hour;
            int      currentMinute = dt.Minute;
            int      currentSecond = dt.Second;

            //create a string for the program title
            String ProgramTitle = "TestRun_" + currentMonth + "_" + currentDay + "_" + currentYear + "-" + currentHour + ":" + currentMinute + ":" + currentSecond;

            Thread.Sleep(2000);
            ProgramTitleCertifiedAssessmentTxt.SendKeys(ProgramTitle);

            //move down to the province selection screen
            IWebElement element = Browser.FindElement(By.Id("ctl00_ContentPlaceHolder1_CFPCActivitiesWizard_ctl03_fb1_ctl06_ctl17_CEComboBox3449685"));   // Put this element in the page bys class

            ElemSet.ScrollToElement(Browser, element);
            // MIKE: Removed a bunch of end lines
            //select alberta
            ProvinceSelectorDrpDn.SelectByIndex(1);
            ProvinceSelectorDrpDn.SelectByText("Alberta (AB)");       // MIKE: I added this line and commented the one above it. Why use index when you know which item you are going to choose? The index might change in the future if more items are added to the select list

            //Fill out the test city
            CityTxt.SendKeys("Test City");
            //fill out the
            PlanningOrganizationTxt.SendKeys("Test");

            //generate a date for these Activity Test
            string date = DateTime.Today.AddDays(-1).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);  // MIKE: I added this line and commented out the below lines. Reduces lines and having seperate varaibles for the start and end doesnt make sense in this case

            //DateTime dt2 = DateTime.Today.AddDays(-1);
            //String startDateText = dt2.Month + "/"  + dt2.Day + "/" + dt2.Year;
            //String completionDateText = dt2.Month + "/" + dt2.Day + "/" + dt2.Year;

            //send the text to the box
            ActivityStartDateTxt.SendKeys(date);
            ActivityCompletionDateTxt.SendKeys(date);

            CreditsClaimedTxt.SendKeys("1");

            ChangedImprovedRdo.Click();
            LearnedNewRdo.Click();
            LearnMoreRdo.Click();

            //scroll to the dissatisfied radio button
            // ElemSet.ScrollToElement(Browser,DissatisfiedRdo);
            ElemSet.ClickAfterScroll(Browser, DissatisfiedRdo);    // MIKE: I added this line and commented the above one. We can talk at meeting

            BiasedRdo.Click();

            //scroll to element
            ElemSet.ClickAfterScroll(Browser, ConfirmedRdo);   // MIKE: I would name these elements with a little more detail. It took me, a new person, a little bit of time to figure out what radio button was for each variable
                                                               // MIKE: Always start with the beginning text when naming elements. For example for this radio button, name it "ThisExperienceConfirmedRdo" instead of just "Confirmed"

            // For some reason, whenever we use Selenium's built in click method here, it triggers the application to add more than
            // 1 credit for the activity/user (We entered "1" into the CreditsClaimed text box above, so only 1 credit should get
            // added for the user). I added a workaround to use the javascript version of a click, and this
            // works (only adds the specified amount of credits) For more info,
            // see https://stackoverflow.com/questions/24571048/selenium-webelement-click-vs-javascript-click-event
            JavascriptUtils.Click(Browser, SubmitButton);
            SubmitButton.SendKeys(Keys.Tab);


            Thread.Sleep(20000);     // MIKE: Definitely add wait criteria here. I see that a popup appears, we can wait on an element in this popup
        }