简体   繁体   中英

How can I increment the result keyword in this method? in selenium c#

private SendGridCompleteRegistrationEmail WaitForBlobEmail(AzureStorageBlobClient blobClient, string containerName, string fileName)
{
    int i = 0;
    SendGridCompleteRegistrationEmail result = null;
    while ((i < 120) && (result == null)) 
    {
        System.Threading.Thread.Sleep(1000);
        result = blobClient.GetJsonBlobContent<SendGridCompleteRegistrationEmail>(containerName, fileName).Result;
        i++;
    }

    Assert.IsNotNull(result, "Failed to retrieve json message for " + fileName + " from " + containerName + " blob");

    return result;
}

Everytime its used I want a new keyword result, result2 etc to be returned

        [TestMethod]
        [DataRow("Manager", "testadmin@markerstudy.com", new string[] { "Foody Fleet" } )]
        [DataRow("Manager", "fleetmanager@visiontrack.com", new string[] { "Foody Fleet", "Fleetingly Employed" })]
        [TestCategory("UserMgt")]
        public void CompleteRegProcessPass_dom(string role, string emailID, string[] fleetNames)
        {
            //is emailID registered if not register

            var blobClient = new AzureStorageBlobClient(AzureStorageBlobClient);
            _regRep.btnAddUser.Click();
            FilterUserTableByEmail(emailID);
            if (FilterUserTableByEmail(emailID) == true)
            {
                //No need to register
            }
            else
            {
                //must register
                objCommon.EnterText(_regRep.firstNameAdd, userName);
                objCommon.EnterText(_regRep.lastNameAdd, "Smithy");
                objCommon.EnterText(_regRep.userEmailAdd, emailID);
                objCommon.EnterText(_regRep.userTelephoneAdd, "12345678901");
                objCommon.Exists(_regRep.userRoleManager(role), 10);
                objCommon.ScrollInToViewAndClick(_regRep.userRoleManager(role));
                //objCommon.Exists(_regRep.chooseFleet, 5);
                for (int i = 0; i < fleetNames.Count(); i++)
                {
                    objCommon.ScrollInToViewAndClick(_regRep.chooseFleet(fleetNames[i]));
                }


                objCommon.Click(_regRep.btnSaveUser);
                System.Threading.Thread.Sleep(1000);


                FilterUserTableByEmail(emailID);





                var result = WaitForBlobEmail(blobClient, "complete-registration", $"{emailID}.json");
                Assert.IsNotNull(result, "Failed to retrieve json message from complete-registration blob");

                objCommon.HoverAndClick(_regRep.UserIcon, _regRep.LogOutLink, driver);
                System.Threading.Thread.Sleep(2000);
                driver.Navigate().GoToUrl(result.TokenUrl);
                System.Threading.Thread.Sleep(2000);
                Actions builder1 = new Actions(driver);
                builder1.MoveToElement(driver.FindElement(By.XPath("//div[@class='vt-login-page__footer']/span"))).Click().Build().Perform();


                System.Threading.Thread.Sleep(2000);
                driver.FindElement(By.Id("email")).SendKeys(emailID);
                driver.FindElement(By.XPath("//input[@id='newPassword']")).SendKeys("cy!NbZtnzAs4T&");
                driver.FindElement(By.XPath("//input[@id='confirmPassword']")).SendKeys("cy!NbZtnzAs4T&");
                driver.FindElement(By.XPath("//button[text()='Set Password']")).Click();
                if (driver.FindElement(By.XPath("//h1[text()='Complete Registration...']")).Displayed)
                {
                    Assert.IsTrue(driver.FindElement(By.XPath("//h1[text()='Complete Registration...']")).Displayed == true);

                }
                else
                {
                    Console.WriteLine("Registration completed successfully.");

                }
            }

            objCommon.EnterText(_regRep.firstNameAdd, userName);
            objCommon.EnterText(_regRep.lastNameAdd, "Smithy");
            objCommon.EnterText(_regRep.userEmailAdd, emailID);
            objCommon.EnterText(_regRep.userTelephoneAdd, "12345678901");
            objCommon.Exists(_regRep.userRoleManager(role), 10);
            objCommon.ScrollInToViewAndClick(_regRep.userRoleManager(role));
            //objCommon.Exists(_regRep.chooseFleet, 5);
            for (int i = 0; i < fleetNames.Count(); i++)
            { 
              objCommon.ScrollInToViewAndClick(_regRep.chooseFleet(fleetNames[i]));
            }


            objCommon.Click(_regRep.btnSaveUser);
            System.Threading.Thread.Sleep(1000);


            FilterUserTableByEmail(emailID);



            var result = WaitForBlobEmail(blobClient, "complete-registration", $"{emailID}.json");
            Assert.IsNotNull(result, "Failed to retrieve json message from complete-registration blob");

            objCommon.HoverAndClick(_regRep.UserIcon, _regRep.LogOutLink, driver);
            System.Threading.Thread.Sleep(2000);
            driver.Navigate().GoToUrl(result.TokenUrl);
            System.Threading.Thread.Sleep(2000);
            Actions builder = new Actions(driver);
            builder.MoveToElement(driver.FindElement(By.XPath("//div[@class='vt-login-page__footer']/span"))).Click().Build().Perform();


            System.Threading.Thread.Sleep(2000);
            driver.FindElement(By.Id("email")).SendKeys(emailID);
            driver.FindElement(By.XPath("//input[@id='newPassword']")).SendKeys("cy!NbZtnzAs4T&");
            driver.FindElement(By.XPath("//input[@id='confirmPassword']")).SendKeys("cy!NbZtnzAs4T&");
            driver.FindElement(By.XPath("//button[text()='Set Password']")).Click();
            if (driver.FindElement(By.XPath("//h1[text()='Complete Registration...']")).Displayed)
            {
                Assert.IsTrue(driver.FindElement(By.XPath("//h1[text()='Complete Registration...']")).Displayed == true);

            }
            else
            {
                Console.WriteLine("Registration completed successfully.");

            }


        }

How about the other way around everytime the original method is called could we count it to make it unique in the main test method? The problem I have is I need to register the login credentials and they use the keyword "result". Please help me write the correct code?

You can create a list and add the result value returned from that function to that list. So that you will have the values returned by the function in each run.

List<SendGridCompleteRegistrationEmail> results = new List<SendGridCompleteRegistrationEmail>();
SendGridCompleteRegistrationEmail result = WaitForBlobEmail(blobClient, "complete-registration", $"{emailID}.json");
results.Add(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM