Created
August 28, 2017 02:22
-
-
Save JitendraZaa/6e0bf9e09bfe8063a49974be7ee6dbaf to your computer and use it in GitHub Desktop.
Sample Project showing how to perform load testing in Salesforce with the help of Selenium and TestNG Parallel execution http://JitendraZaa.com/blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.jitendrazaa; | |
| import java.util.concurrent.TimeUnit; | |
| import org.openqa.selenium.By; | |
| import org.openqa.selenium.WebDriver; | |
| import org.testng.AssertJUnit; | |
| import org.testng.annotations.Test; | |
| public class ConcurrentApexError extends TestBase{ | |
| @Test(invocationCount = 20,threadPoolSize = 20) | |
| public void verifyLonGRunningProcess() { | |
| System.out.printf("Thread Id : %s%n", Thread.currentThread().getId()); | |
| WebDriver driver = DriverFactory.getInstance().getDriver(); | |
| DriverFactory.getInstance().getDriver().manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS); | |
| DriverFactory.getInstance().getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | |
| driver.get("https://login.salesforce.com/"); | |
| driver.findElement(By.id("username")).clear(); | |
| driver.findElement(By.id("username")).sendKeys("SalesforceUserName"); | |
| driver.findElement(By.id("password")).clear(); | |
| driver.findElement(By.id("password")).sendKeys("SomePassword"); | |
| driver.findElement(By.id("Login")).click(); | |
| wait(10); | |
| driver.get("https://zaa-dev-ed.my.salesforce.com/apex/LongRunningProcesses"); | |
| for(int i=1,j=5,k=3;i<=100;i++,j=j+7,k=k+7){ | |
| System.out.printf("Thread - "+Thread.currentThread().getId()+" - j_id0:timer"+i+":j_id"+k+":frm1:j_id"+j+"\n"); | |
| driver.findElement(By.id("j_id0:timer"+i+":j_id"+k+":frm1:j_id"+j)).click(); | |
| } | |
| wait(60*2); | |
| AssertJUnit.assertEquals(driver.findElement(By.id("j_id0:timer1:j_id3:frm1:rsltPanel")).getText(),"Process completed in 110 sec"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.jitendrazaa; | |
| import static org.testng.Assert.fail; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.nio.file.Paths; | |
| import org.apache.commons.io.FileUtils; | |
| import org.openqa.selenium.OutputType; | |
| import org.openqa.selenium.TakesScreenshot; | |
| import org.testng.ITestResult; | |
| import org.testng.annotations.AfterClass; | |
| import org.testng.annotations.AfterMethod; | |
| import org.testng.annotations.BeforeClass; | |
| public class TestBase { | |
| protected String firefox_driverPath = "\\webdrivers\\geckodriver.exe"; | |
| protected String chrome_driverPath = "\\webdrivers\\chromedriver.exe"; | |
| StringBuffer verificationErrors = new StringBuffer(); | |
| @BeforeClass(alwaysRun = true) | |
| public void setUp() throws Exception { | |
| String rootPath = Paths.get("").toAbsolutePath().toString(); | |
| System.out.printf("Setup Thread Id : %s%n", Thread.currentThread().getId()); | |
| System.setProperty("webdriver.chrome.driver", rootPath+chrome_driverPath); | |
| } | |
| @AfterClass(alwaysRun = true) | |
| public void tearDown() throws Exception { | |
| String verificationErrorString = verificationErrors.toString(); | |
| if (!"".equals(verificationErrorString)) { | |
| fail(verificationErrorString); | |
| } | |
| } | |
| protected void wait(int seconds){ | |
| try{ | |
| for(int i=0;i<seconds;i++){ | |
| Thread.sleep(1000); | |
| int pauseLeft = seconds - (i+1) ; | |
| System.out.printf("pause for 1 seconds... "+pauseLeft+"sec left in Thread - "+Thread.currentThread().getId()+"\n"); | |
| } | |
| }catch(Exception e){ | |
| e.printStackTrace(); | |
| } | |
| } | |
| @AfterMethod | |
| public void takeScreenShotOnFailure(ITestResult testResult) throws IOException { | |
| if (testResult.getStatus() == ITestResult.FAILURE) { | |
| File scrFile = ((TakesScreenshot)DriverFactory.getInstance().getDriver()).getScreenshotAs(OutputType.FILE); | |
| FileUtils.copyFile(scrFile, new File("errorScreenshots\\" + testResult.getName() + "-" | |
| + System.currentTimeMillis() + ".jpg")); | |
| } | |
| DriverFactory.getInstance().removeDriver(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment