0

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)

asked Nov 12, 2018 at 7:14

2 Answers 2

1

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.

answered Nov 12, 2018 at 9:13
2
  • Actually, a JSON file would be faster, easier to maintain, and not Windows/Excel-dependent. Commented Nov 12, 2018 at 20:42
  • I'll try for both method and back for the result Commented Nov 13, 2018 at 2:15
0

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.

answered Nov 14, 2018 at 23:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.