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("user.1@gmail.com");
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)

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.

  • Actually, a JSON file would be faster, easier to maintain, and not Windows/Excel-dependent. – João Farias Nov 12 '18 at 20:42
  • I'll try for both method and back for the result – BetaTester Nov 13 '18 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[]{
          "email1@do.men",
          "email2@do.men",
          "email3@do.men",
          "email4@do.men"
        };

        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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.