Examples
Example 1
The Selenium driver is started once and stopped at the end of the whole test. Only one User Path is created or updated.
package com.selenium.test;import static com.neotys.selenium.proxies.NLWebDriverFactory.addProxyCapabilitiesIfNecessary;import java.io.File;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.remote.DesiredCapabilities;import com.neotys.selenium.proxies.NLWebDriver;import com.neotys.selenium.proxies.NLWebDriverFactory;public class UnitTest {private static final String CHROME_DRIVER_PATH = "C:\\Selenium\\chromedriver.exe";static {final File file = new File(CHROME_DRIVER_PATH);System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());}static NLWebDriver driver;@BeforeClasspublic static void before() {final ChromeDriver webDriver = new ChromeDriver(addProxyCapabilitiesIfNecessary(new DesiredCapabilities()));// projectPath used to open NeoLoad project, null to use currently opened Project.final String projectPath = "C:\\Users\\anouvel\\Documents\\NeoLoad Projects\\v5.3\\Sample_Project\\Sample_Project.nlp";driver = NLWebDriverFactory.newNLWebDriver(webDriver, "SeleniumUserPath", projectPath);}@Testpublic void testSubmit() {driver.startTransaction("home1");driver.get("http://ushahidi.demo.neotys.com/");driver.startTransaction("reports");driver.findElement(By.id("mainmenu")).findElements(By.tagName("a")).get(1).click();driver.startTransaction("submit");driver.findElement(By.partialLinkText("SUBMIT")).click();}@Testpublic void testGetAlerts() {driver.startTransaction("home2");driver.get("http://ushahidi.demo.neotys.com/");driver.startTransaction("alerts");driver.findElement(By.partialLinkText("GET ALERTS")).click();}@AfterClasspublic static void after() {if (driver != null) {driver.quit();}}}
Example 2
The Selenium driver is started before each test and stopped at the end of each test. One User Path is created or updated per test.
package com.selenium.test;import static com.neotys.selenium.proxies.NLWebDriverFactory.addProxyCapabilitiesIfNecessary;import java.io.File;import org.junit.After;import org.junit.Before;import org.junit.Rule;import org.junit.Test;import org.junit.rules.TestName;import org.openqa.selenium.By;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.remote.DesiredCapabilities;import com.neotys.selenium.proxies.NLWebDriver;import com.neotys.selenium.proxies.NLWebDriverFactory;public class UnitTest2 {private static final String CHROME_DRIVER_PATH = "C:\\Selenium\\chromedriver.exe";static {final File file = new File(CHROME_DRIVER_PATH);System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());}@Rulepublic TestName testName = new TestName();NLWebDriver driver;@Beforepublic void beforeTest() {final ChromeDriver webDriver = new ChromeDriver(addProxyCapabilitiesIfNecessary(new DesiredCapabilities()));final String projectPath = "C:\\Users\\anouvel\\Documents\\NeoLoad Projects\\v5.3\\Sample_Project\\Sample_Project.nlp";driver = NLWebDriverFactory.newNLWebDriver(webDriver, testName.getMethodName(), projectPath);}@Testpublic void testSubmit() {driver.startTransaction("home");driver.get("http://ushahidi.demo.neotys.com/");driver.startTransaction("reports");driver.findElement(By.id("mainmenu")).findElements(By.tagName("a")).get(1).click();driver.startTransaction("submit");driver.findElement(By.partialLinkText("SUBMIT")).click();}@Testpublic void testGetAlerts() {driver.startTransaction("home");driver.get("http://ushahidi.demo.neotys.com/");driver.startTransaction("alerts");driver.findElement(By.partialLinkText("GET ALERTS")).click();}@Testpublic void testSubmitIncident(){driver.startTransaction("home");driver.get("http://ushahidi.demo.neotys.com/");driver.startTransaction("submit-incident");driver.findElement(By.className("submit-incident")).click();driver.findElement(By.id("incident_title")).sendKeys("Title");driver.findElement(By.id("incident_description")).sendKeys("Description");driver.findElement(By.id("location_name")).sendKeys("Gémenos, France");driver.findElement(By.cssSelector("input[type='checkbox'][value='2']")).click();driver.findElement(By.className("btn_submit")).click();}@Afterpublic void afterTest() {if (driver != null) {driver.quit();}}}
Home