The Selenium integration allows customers to run their Selenium test automation scripts on real browsers in the Perfecto-secured and enterprise-grade testing cloud.Create your Selenium tests in any supported language and any supported test framework.
Prerequisites :
Design and develop test cases of your application and the same you passed to Devaten application as usecase.
To start/stop recording your testcase/ usecase call the start/stop recording API before/after the test case/usecase.
In order to get the detailed report of your test case/ usecase call the generate report API of Devaten.
In the Selenium-TestNG Automation framework:
First, set up the test environment using
@BeforeSuite public void setup() { System.setProperty("webdriver.chrome.driver", "H:\\DevatenData\\Devaten_Automation\\chromedriver\\chromedriver.exe"); System.out.print("Inside setUp....... "); String browserName = readApplicationProperties("browserForTestRun"); initializeDriver(browserName); driver.manage().window().maximize(); loadApplicationByURL(); }
In @BeforeSuite initialize the browser and load your application on which you want to automate.
Prepared the test case of your application:
@Test(priority = 1)
public void home() throws InterruptedException {
waitForUserInterfaceToLoad(AppConstants.DEFAULT_WAIT_TIME);
driver.navigate().refresh();
EventsUtil.clickWebElementr(By.xpath(readLocatorsProperties("Home_Page")));
waitForUserInterfaceToLoad(AppConstants.DEFAULT_WAIT_TIME);
}
In the above code, the TestNG @Test annotation method is used for writing a test case to which assign the test priority and written the simple test case to click the Home_page of my application.
But here I want to analyze the performance of the database after execution of the test case home. So here implemented the start/stop recording functionality of the Devaten application
Before the test case of the application is execute implement Devaten start recording REST API
@Parameters({ "TestName" })
@BeforeTest
public void callStartRecording(String testName) throws InterruptedException {
Response res = RestAssured.given().header("Authorization", "Bearer " + accessToken).header("applicationIdentifier", readApplicationProperties("applicationIdentifier"))
.get(readApplicationProperties("Supermon_url") + "devaten/data/startRecording?usecaseIdentifier="
+ testName);
//System.out.println(res.getStatusCode());
Thread.sleep(2500);
}
In the above code @Parameters({TestName}) is the Name of the test which you can give in your testng.xml file this way
In the above code @Parameters({TestName}) is the Name of the test which you can give in your testng.xml file this way
And pass the method name i.e. test case written namely home
<methods>
<include name="home" />
</methods>
In this way implemented the start recording API Devaten
Response res = RestAssured.given().header("Authorization", "Bearer " + accessToken) .header("applicationIdentifier", readApplicationProperties("applicationIdentifier")) .get(readApplicationProperties("Devaten_url")+"devaten/data/startRecording?usecaseIdentifier="+ testName);
In the above code, the start recording API of Devaten accepts applicationIdentifier which passes through the properties file by declaring in that, and the second parameter is usecaseIdentifier=”testName” declared in testNG.xml file.
After start recording implemented the stop recording using
@Parameters({ "TestName" }) @AfterTest public void callStopRecording(String testName) throws InterruptedException { Response res = RestAssured.given().header("Authorization", "Bearer " + accessToken) .header("applicationIdentifier", readApplicationProperties("applicationIdentifier")) .get(readApplicationProperties("Devaten_url") + "devaten/data/stopRecording?usecaseIdentifier=" + testName + "&inputSource=batFile"); // System.out.println(res.getStatusCode()); Thread.sleep(2500); }
Here Passed the same parameter of which pass in the start recording. And use @AfterTest annotation so that it can stop the recording after executing the test
Get a report after executing the use cases using
@AfterSuite
public void close() throws InterruptedException {
Response report = RestAssured.given().header("Authorization", "Bearer " + accessToken)
.header("applicationIdentifier", readApplicationProperties("applicationIdentifier"))
.get(readApplicationProperties("Supermon_url") + "devaten/data/generateReport");
//System.out.println(report.getBody().asString());
try (FileWriter file = new FileWriter("report/response.json")) {
// File Writer creates a file in write mode at the given location
file.write(report.getBody().asString());
// write function is use to write in file,
// here we write the Json object in the file
file.flush();
} catch (IOException e) {
e.printStackTrace();
}
Thread.sleep(2000);
// waitForUserInterfaceToLoad(Constant.DEFAULT_WAIT_TIME);
driver.close();
}
For getting a report used the Devaten generate report API which is implemented in the @AfterSuite annotation method. The report is stored in the response.json file.
You can view these executed use cases on your Devaten dashboard.
Copyright © 2024 Devaten, All rights reserved.