1

I have created automation script to test WEB UI using selenium C#. I dont want to hardcode the login details and want to send those values through JSON input. How do I convert Json inputs in C#.

 IWebDriver webdriver = new ChromeDriver(@"D:\Selenium\Chrome_90V");
        Loginpage LoginP = new Loginpage(webdriver);
        Homepage homep = new Homepage(webdriver);
        DataJson Js = new DataJson();
        
        webdriver.Navigate().GoToUrl("https://login.microsoftonline.com");
        //timewait
        TimeSpan timeSpan = TimeSpan.FromSeconds(20);
        webdriver.Manage().Timeouts().ImplicitWait = timeSpan;
        //emailidinput
        LoginP.setemail("**[email protected]**");
        LoginP.clicknext();


       

How do I tell my code to use JSON inputs through class.

1 Answer 1

1

I found solution for this and would like to post it here, if someone else is looking for this.

First create Json file in and put the values in array as: { "key":"value"; "email": "[email protected]";}

Next create a new Cs file and convert json file to Csharp class Login { public string Key{ get; set; } public string email { get; set; } }

next create a new Cs file to parse the data class DataSourceParser { public static Login populateLogin() { string Loginjson = File.ReadAllText(@""); Login login = JsonConvert.DeserializeObject(Loginjson); return login; } }

Now update your test script mentioned in my query as: Login login = DataSourceParser. PopulateLogin(); instead of "DataJson Js = new DataJson();"

verify all string details appears at login.

instead of providing mailid use LoginP.setemail**(login.emailid);**

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.