Local website testing
Example test with Tunnel
Let's get started with running your first test using the TestingBot Tunnel. Assuming you've followed the previous steps, the tunnel should be started up and ready for usage.
Selenium WebDriver test in Java
The example will be created in Java, using Selenium WebDriver to connect to the TestingBot browser grid. By using the tunnel, you will be able to run tests against a website running on your local machine or staging environment.
public class JavaSample {
public static final String URL = "http://localhost:4445/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "chrome");
caps.setCapability("version", "latest");
caps.setCapability("platform", "WIN10");
caps.setCapability("name", "My First Tunnel Test");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("http://www.google.com/ncr");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("TestingBot");
element.submit();
System.out.println(driver.getTitle());
driver.quit();
}
}
By using the URL localhost:4445
your test will go through the tunnel and the test VM on TestingBot will automatically use the same tunnel to access the websites you are testing.
Similarly, you can use a tunnelIdentifier
as a capability in your test to indicate to TestingBot that you want to run a test through the tunnel labeled with the same tunnelIdentifier
. This method does not require changing the URL to localhost:4445
.
public class JavaSample {
public static final String URL = "http://hub.testingbot.com/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "chrome");
caps.setCapability("version", "latest");
caps.setCapability("platform", "WIN10");
caps.setCapability("tunnelIdentifier", "my-first-tunnel");
caps.setCapability("name", "My First Tunnel Test");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("http://www.google.com/ncr");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("TestingBot");
element.submit();
System.out.println(driver.getTitle());
driver.quit();
}
}
The example above assumes you've started the tunnel with
--tunnel-identifier my-first-tunnel
.
Shared TestingBot Tunnel
Using the last approach, you can share one or more tunnels with team members.
By specifying a tunnelIdentifier
everyone in the organization can use the same tunnel in their tests.