My requirement is to enter different usernames to test registration page. So, i want to generate random usernames by using java script.
Using Csharp
IJavaScriptExecutor js= driver as IJavaScriptExecutor;
string username=(string)js.ExecuteScript("return 'anji'+Math.floor(Math.random()*1111)");
Using Java
JavascriptExecutor js = (JavascriptExecutor) driver;
String username=(String)js.executeScript("return 'anji'+Math.floor(Math.random()*1111)");
We can pass this variable to username filed.
Using Csharp
IJavaScriptExecutor js= driver as IJavaScriptExecutor;
string username=(string)js.ExecuteScript("return 'anji'+Math.floor(Math.random()*1111)");
Using Java
JavascriptExecutor js = (JavascriptExecutor) driver;
String username=(String)js.executeScript("return 'anji'+Math.floor(Math.random()*1111)");
We can pass this variable to username filed.
No comments:
Post a Comment