We can use Sauce Labs for executing tests on Different Environment using SauceLabs
Key thing is we can set various capabilities to configure on which environment we want to execute test cases
Lets create a Trial Account on Sauce Labs
Steps
1.) Login with Account and Go To User Settings
2.) Copy the Access Key
3.) Use the sample Code written below
package demo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class SampleSauceTest {
public static final String USERNAME = "neeraj19a";
public static final String ACCESS_KEY = "81f32882-2388------ Your Access Key";
public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = DesiredCapabilities.safari(); // Here we are Setting Safari , because we are using Safari Browser for Testing, we can use Any Browser based on your need
caps.setCapability("platform", "macOS 10.14"); // On OS on which you want to execute Test case
caps.setCapability("version", "12.0"); // Version of OS
caps.setCapability("screenResolution", "1024x768"); // Resolution of browser
caps.setCapability("name", "Google Testing"); // Name of the Test run
caps.setCapability("capturePerformance", true); // To capture Network and check performance
caps.setCapability("extendedDebugging", true); // To capture Network and check performance
caps.setCapability("buildNumber", "3.0");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("https://google.com");
System.out.println(driver.getTitle());
driver.findElement(By.name("q")).click();
driver.findElement(By.name("q")).sendKeys("hello");
driver.quit();
System.out.println("Test completed");
}
}
We can also use Platform Configurator
https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
This will help us in providing the Desired Capabilities that we will need for setting Up test Execution in any Environment
Copy the Desired Capabilities (Generated when you select OS and browser)
This is how the Test Execution Looks like see that Network is also captured as we used "capturePerformance", true and "extendedDebugging", true in above Sample Code
caps.setCapability("capturePerformance", true);
caps.setCapability("extendedDebugging", true);
No comments:
Post a Comment