mardi 26 juillet 2016

Getting text in element using SpecFlow and Selenium

I am getting an error in my SpecFlow unit test:

System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary. at TechTalk.SpecFlow.SpecFlowContext.Get[T](String key) at F*****.Live.PS.*******.Steps.*******.EnterStagingDateAndSaveSteps.ThenUserSeesInNEXTRE_ENROLMENTWINDOWTextFieldInPENSIONASSESSMENTDATESPageInPENSIONModule(String p0) in c:\Git\LivePeopleSystemTests\Fourth.Live.PS.AutomationTests\F*****.Live.PS.*******.Steps*******\EnterStagingDateAndSaveSteps.cs:line 175

Here is the referenced method in EnterStagingDateAndSaveSteps.cs

[Then(@"user sees ""(.*)"" in NEXT RE-ENROLMENT WINDOW Text Field in PENSION ASSESSMENT DATES page in PENSION module")]
    public void ThenUserSeesInNEXTRE_ENROLMENTWINDOWTextFieldInPENSIONASSESSMENTDATESPageInPENSIONModule(string p0)
    {
        // GetNextReEnrollmentWindow
        string validator =
            ScenarioContext.Current.Get<PensionAssessmentDates>("_nextReEnrollmentWindow")
                .GetNextReEnrollmentWindow();
        Assert.IsTrue(validator == p0);
    }

(I also tried return Driver.WaitAndGetText(_nextReEnrollmentWindow); in there)

so it looks like the key _nextReEnrollmentWindow doesn't exist, but here it is defined in PensionAssessmentDates.cs:

private readonly By _nextReEnrollmentWindow = By.Id("NextReEnrollmentWindow"); 

enter image description here

and here is the actual web-page I am trying to test showing the element exists:

enter image description here

I'd be grateful for any pointers or advice on what I have missed which is causing my unit test to stop as below:

    EnterStagingDateAndSaveSteps.WhenUserClicksSAVEButtonUnderAUTOMATICENROLMENTATSTAGINGDATEFrameInPENSIONASSESSMENTDATESPageInPENSIONModule() (0.7s)
Then user sees "02 Oct 2019 to 02 Apr 2020" in NEXT RE-ENROLMENT WINDOW Text Field in PENSION ASSESSMENT DATES page in PENSION module
-> error: The given key was not present in the dictionary.

Aucun commentaire:

Enregistrer un commentaire