Currently I have issue, when a content get a multiple like from different user, the content will be unable to access due to error (let's say get a likes from 100 different user)
I just manually edit my code below, by changing email address;
//new user sign up
driver.findElement(By.id("email")).sendKeys("[email protected]");
driver.findElement(By.id("name")).sendKeys("New User 1");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.id("submit")).click();
//new user like
driver.findElement(By.id("like")).click();
//new user log out
driver.findElement(By.id("logout")).click();
How do I automatically loop code above but with new email address?
(I prefer still using Selenium if possible, because in my Opinion I want to know exact number that trigger the error and control the new user information rather than using stress test tool, and I thought it will be easier to modify for other case such multiple comment, report, feedback, etc)
2 Answers 2
Follow the below steps:
- Create a excel and store all the data's like email, password and name.
- Use Apache POI and Dataprovider to read values from excel and pass to the automation scripts.
- Loop through registration process to get work for multiple users with different values in the excel.
(OR)
Follow the methods present in the url to generate random email id's while automation and then loop through each values.
-
Actually, a JSON file would be faster, easier to maintain, and not Windows/Excel-dependent.João Farias– João Farias2018年11月12日 20:42:39 +00:00Commented Nov 12, 2018 at 20:42
-
I'll try for both method and back for the resultBetaTester– BetaTester2018年11月13日 02:15:31 +00:00Commented Nov 13, 2018 at 2:15
You can just keep your email list in the array like it is shown below:
public static void main(String[] args) {
String[] emails = new String[]{
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
};
for(String email: emails){
//new user sign up
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("name")).sendKeys("New User 1");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.id("submit")).click();
//new user like
driver.findElement(By.id("like")).click();
//new user log out
driver.findElement(By.id("logout")).click();
}
}
However if you do not use any test frameworks like JUnit of TestNg to run your tests you will have to take care of some pre-test and post-test code to be executed (like start browser, close browser, etc.).
Test frameworks also support the mechanisms that can feed each your particular test with a single test entry from your array so that you describe one test and run one time for each of your test data entry.
Take a look at JUnit or TestNg and if you'll have issues with the approach, I'll help you to set up a sample code.
Explore related questions
See similar questions with these tags.