package com.iontorrent.ampliseq.web.smoke.locustTask; import java.io.File; import java.util.HashMap; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.PageLoadStrategy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import com.github.myzhan.locust4j.AbstractTask; import com.github.myzhan.locust4j.Locust; import com.github.myzhan.locust4j.taskset.AbstractTaskSet; import com.github.myzhan.locust4j.taskset.WeighingTaskSet; import com.jayway.restassured.response.Response; import static com.jayway.restassured.RestAssured.given; /** * @author myzhan */ public class WeighingRps { private static class TestTask extends AbstractTask { public int weight; public String name; public static WebDriver drv; WebDriverWait wait = null; public TestTask(String name, int weight) { this.name = name; this.weight = weight; } @Override public int getWeight() { return this.weight; } @Override public String getName() { return this.name; } public void loadDriver() { //ChromeDriver properties for Selenium WebDriver declared here } public void loginHomepage() { drv.get("httsps: test url"); wait.until(ExpectedConditions.elementToBeClickable(By.id("signInButton"))); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signInButton"))); drv.findElement(By.id("signInButton")).click(); } public void qaRedirection() { wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("next-button"))); wait.until(ExpectedConditions.elementToBeClickable(By.id("next-button"))); drv.findElement(By.id("username-field")).sendKeys("username"); drv.findElement(By.id("next-button")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signin-button"))); wait.until(ExpectedConditions.elementToBeClickable(By.id("signin-button"))); drv.findElement(By.id("password-field")).sendKeys("password"); drv.findElement(By.id("signin-button")).click(); } public void applicaitonRedirection() { wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("abcdde"))); wait.until(ExpectedConditions.elementToBeClickable(By.id("cdsadadd"))); } public void pageLoad() { drv.findElement(By.id("panel")).click(); } public void quitDriver() { drv.quit(); } @Override public void execute() { loadDriver(); long start = System.currentTimeMillis(); loginHomepage(); Locust.getInstance().recordSuccess("launch", "test1", getResponseTime(start), 1); start = System.currentTimeMillis(); qaRedirection(); Locust.getInstance().recordSuccess("launch and login to", "myApplication", getResponseTime(start), 1); start = System.currentTimeMillis(); applicaitonRedirection(); Locust.getInstance().recordSuccess("Come back to application", "HomePage", getResponseTime(start), 1); start = System.currentTimeMillis(); pageLoad(); Locust.getInstance().recordSuccess("page load", "", getResponseTime(start), 1); quitDriver(); } } public static long getResponseTime(long start) { return System.currentTimeMillis() - start; } public static void main(String[] args) { Locust locust = Locust.getInstance(); locust.setMasterHost("127.0.0.1"); locust.setMasterPort(5557); locust.setMaxRPS(100); AbstractTaskSet taskSet = new WeighingTaskSet("test", 1); TestTask obj = new TestTask("login", 10); taskSet.addTask(obj); locust.run(taskSet); } }