DevOps | Software Automation | Continuous Integration
Back in days when I was working with Ruby on a MacBook Pro, I got Curl. However, now as I am using a PC in a .NET shop, I need to use compatible technology to test API – HttpClient is my solution.
Install the Web API Client Libraries via Package Manager Console
Install-Package Microsoft.AspNet.WebApi.Client
Sample code as below:
I have encountered a situation where I need to click on a button in order to upload a file.
I test this using Selenium C# by:
1. Entering the file path into the box
driver.FindElement(By.Id(“uploadFile”)).SendKeys(“C/testFile.txt”);
2. Calling the Javascript function to simulate what happens when “Upload” button is clicked
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string script = “__doPostBack(‘uploadFileButton’,”)”;
js.ExecuteScript(script);
//This is how we can make the step definitions reusable
This post contains the key commands for Selenium in C#
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(https://google.com/);
driver.FindElement(By.XPath(“//input[@name=’sName’]”)).Clear();
driver.FindElement(By.XPath(“//input[@name=’sName’]”).SendKeys(“Testing 123”);
driver.FindElement(By.XPath(“//input[@name=’sName’]”).Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement employeeSearch = wait.Until((d) =>
{ return
d.FindElement(
By.XPath(
“/html/body[@id=’ctl00__objBodyTag’]/form[@id=’aspnetForm’]/table/tbody/tr[2]/td/table/tbody/tr/td[@id=’menuCell’]/div[@id=’menu’]/div/ul/li[@id=’user’]/ul/li[2]/a”));
});
employeeSearch.Click();
© 2023 Chuan Chuan Law
Theme by Anders Noren — Up ↑