1

I have created login scripts using hub and nodes.

  • execute command to start selenium server
  • Started a Hub along with selenium server.
  • Started multiple Nodes.
  • Worked on scripts and run for Firefox.

But, what should I do to run login script for concurrent users using multiple browser ?

  • Try to use TESTNG with XML. – Helping Hands Feb 2 '15 at 12:18
3

This load test article is a great walkthru for your scenario - http://www.mkyong.com/unittest/testng-selenium-load-testing-example/

0

You can checkout my sample test automation project for OrangHRM using Selenium

https://github.com/qamate/orangehrm-selenium-automation

Below is my TestNG.xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="smoke-test-suite" parallel="tests" thread-count="5">
<parameter name="ReportLocation" value="reports"></parameter>
<parameter name="remoteURL" value="http://localhost:4444/wd/hub"></parameter>
<!-- <parameter name="baseURL" value="http://opensource.demo.orangehrmlive.com/"></parameter> -->
 <parameter name="baseURL" value="http://www.google.com/"></parameter>
    <parameter name="internal" value="false"></parameter>
    <!--
        <test name="test_ff" >
            <parameter name="OS" value="WIN8_1"></parameter>
            <parameter name="browser" value="firefox"></parameter>
            <parameter name="version" value="34"></parameter>

            <classes>
               <class name="com.qamate.orangehrm_selenium_automation.Tests.LoginTest" >
               </class>
            </classes>
        </test>


            <test name="test_ie" >
                <parameter name="OS" value="WIN8_1"></parameter>
                <parameter name="browser" value="internet explorer"></parameter>
                <parameter name="version" value="34"></parameter>
                <classes>
                    <class name="com.qamate.orangehrm_selenium_automation.Tests.LoginTest" >
                    </class>
                </classes>
            </test>

            <test name="test_chrome" >
                <parameter name="OS" value="WINDOWS"></parameter>
                <parameter name="browser" value="chrome"></parameter>
                <parameter name="version" value="ANY"></parameter>
                <classes>
                    <class name="com.qamate.orangehrm_selenium_automation.Tests.LoginTest" >
                    </class>
                </classes>
            </test>-->
    <test name="test_chrome" >
        <parameter name="OS" value="WINDOWS"></parameter>
        <parameter name="browser" value="chrome"></parameter>
        <parameter name="version" value="ANY"></parameter>
        <classes>
            <class name="com.qamate.orangehrm_selenium_automation.Tests.GoogleTest" >
            </class>
        </classes>
    </test>
<!--
            <test name="reportingTest" >
                <classes>
                   <class name="com.kagrana.base.BaseActionsTest" >
                   </class>
                </classes>
            </test>
            <test name="reportingTest1" >
                <classes>
                   <class name="com.kagrana.base.BaseActionsTest1" >
                   </class>
                </classes>
            </test>
            <test name="reportingTest2" >
                <classes>
                   <class name="com.kagrana.base.BaseActionsTest2" >

                   </class>
                </classes>
            </test>
            <test name="reportingTest3" >
                <classes>
                   <class name="com.kagrana.base.BaseActionsTest3" >

                   </class>
                </classes>
            </test>
            <test name="reportingTest4" >
                <classes>
                   <class name="com.kagrana.base.BaseActionsTest4" >

                   </class>
                </classes>
            </test>
             -->
</suite>

In the above example, you can see the way I am specifying different browser combinations for different tests as parameters. From your test class you can read these parameters.

E.g. See below class file.

package in.mayurshah.base;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import in.mayurshah.DTO.WebDriverConfig;
import in.mayurshah.util.Log;
import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

import in.mayurshah.DTO.TestCase;

public abstract class BaseActions {
    protected WebDriver driver;
    protected static Log log;
    protected WebDriverConfig config;
    protected String baseURL;
    protected TestCase testCase;
    private static int testCaseCount = 1;

    /**
     * This gets invoked even before suite starts.
     * @param ReportLocation - Provide location where you want to store the report
     */
    @Parameters({"ReportLocation"})
    @BeforeSuite
    public void beforeSuite(@Optional String ReportLocation){
        log = new Log();
        log.setReportDirectory(ReportLocation);
    }
    @BeforeMethod
    @Parameters({ "remoteURL", "baseURL", "OS", "browser",
            "version", "internal" })
    public void beforeTest(String remoteURL, String baseURL,
            String OS, String browser, String version, String internal)
            throws IOException {
        this.testCase = new TestCase();
        this.testCase.setExecutionEnvironment("{browser:"+browser+",browserVersion:"+version+",OperatingSystem:"+OS+"}");
        this.testCase.setParentURL(baseURL);
        this.testCase.setTestCaseId("KT"+testCaseCount++);
        this.testCase.setScreenshotDirectory(log.getReportDirectory()+"\\images");
        config = new WebDriverConfig();
        config.setRemoteURL(remoteURL);
        this.baseURL = baseURL;
        config.setOS(OS);
        config.setBrowserName(browser);
        config.setBrowserVersion(version);
        config.setIntenal(Boolean.parseBoolean(internal));
        driver = xRemoteWebDriver.getInstance(config, log);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get(this.baseURL);
    }

    @AfterMethod
    public void afterTest(ITestResult itr) {
        testCase.setExecutionTime((itr.getEndMillis() - itr.getStartMillis()));
        testCase.setTestCaseName(itr.getName());
        log.addTestCase(testCase);
        try {
            driver.close();
        } catch (Exception ignore) {

        }
        try {
            driver.quit();
        } catch (Exception ignore) {

        }
    }
    @AfterSuite
    public void afterSuite(ITestContext itc) throws IOException{
        log.setTestSuiteName(itc.getSuite().getName());
        log.writeReport();
        log.zipAndEmailFile();
    }

}

Hope that helps!

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.