Skip to content

Commit fb50219

Browse files
author
shalini-90
committed
updated with the test name and factory method
1 parent fcaa02a commit fb50219

6 files changed

Lines changed: 96 additions & 34 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11

22
.DS_Store
3+
/.idea
4+
/log
5+
/logs
6+
/target

browserstack.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ framework: testng
3030
# Available options:
3131
# app: '/path/to/local/app.apk'
3232
# OR
33-
# app: 'bs://<app-id>' # App URL returned when uploading the app to BrowserStack manually
33+
app: bs://9956628e64b1fe6243e24fafd2e3dec3b741a774
3434
# Visit https://www.browserstack.com/docs/app-automate/appium/set-up-tests/specify-app for more options
35-
app: ./WikipediaSample.apk
35+
#app: ./WikipediaSample.apk
3636

3737
# =======================================
3838
# Platforms (Browsers / Devices to test)
@@ -63,8 +63,8 @@ source: testng:appium-intellij:v1.1.6
6363
# ==========================================
6464
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
6565
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
66-
browserstackLocal: true # <boolean> (Default false)
67-
browserstackAutomation: false
66+
browserstackLocal: false # <boolean> (Default false)
67+
#browserstackAutomation: true
6868
# Options to be passed to BrowserStack local in-case of advanced configurations
6969
# browserStackLocalOptions:
7070
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
@@ -82,3 +82,8 @@ consoleLogs: errors # <string> Remote browser's console debug levels to be print
8282
# Test Observability is an intelligent test reporting & debugging product. It collects data using the SDK. Read more about what data is collected at https://www.browserstack.com/docs/test-observability/references/terms-and-conditions
8383
# Visit observability.browserstack.com to see your test reports and insights. To disable test observability, specify `testObservability: false` in the key below.
8484
testObservability: true
85+
percy: false
86+
logLevel: debug
87+
appiumVersion: 2.12.1
88+
testContextOptions:
89+
skipSessionName: true

config/appium.testng.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<suite name="AppiumTest" parallel="methods" thread-count="40">
44
<test name="AppiumTest">
55
<classes>
6-
<class name="com.browserstack.perftest.MashReqAppPerf" />
6+
<class name="com.browserstack.perftest.TestDataFactory" />
77
</classes>
88
</test>
99
</suite>

pom.xml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24
<modelVersion>4.0.0</modelVersion>
35

46
<groupId>com.browserstack</groupId>
@@ -29,11 +31,18 @@
2931
</dependency>
3032

3133
<dependency>
32-
<groupId>com.browserstack</groupId>
33-
<artifactId>browserstack-java-sdk</artifactId>
34-
<version>LATEST</version>
35-
<scope>compile</scope>
36-
</dependency>
34+
<groupId>com.browserstack</groupId>
35+
<artifactId>browserstack-java-sdk</artifactId>
36+
<version>LATEST</version>
37+
<scope>compile</scope>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.seleniumhq.selenium</groupId>
42+
<artifactId>selenium-java</artifactId>
43+
<version>4.27.0</version>
44+
<scope>test</scope>
45+
</dependency>
3746

3847
</dependencies>
3948

@@ -55,7 +64,10 @@
5564
<version>3.8.0</version>
5665
</plugin>
5766
<plugin>
58-
<artifactId>maven-surefire-plugin</artifactId><configuration><argLine>-javaagent:"${com.browserstack:browserstack-java-sdk:jar}"</argLine></configuration>
67+
<artifactId>maven-surefire-plugin</artifactId>
68+
<configuration>
69+
<argLine>-javaagent:"${com.browserstack:browserstack-java-sdk:jar}"</argLine>
70+
</configuration>
5971
<version>2.22.1</version>
6072
</plugin>
6173
<plugin>

src/test/java/com/browserstack/perftest/MashReqAppPerf.java

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,78 @@
44
import io.appium.java_client.AppiumClientConfig;
55
import io.appium.java_client.android.AndroidDriver;
66
import io.appium.java_client.android.options.UiAutomator2Options;
7+
import org.openqa.selenium.JavascriptExecutor;
78
import org.openqa.selenium.MutableCapabilities;
89
import org.openqa.selenium.WebElement;
910
import org.openqa.selenium.support.ui.ExpectedConditions;
1011
import org.openqa.selenium.support.ui.WebDriverWait;
12+
import org.testng.ITest;
13+
import org.testng.ITestContext;
14+
import org.testng.ITestNGMethod;
1115
import org.testng.annotations.AfterMethod;
1216
import org.testng.annotations.BeforeMethod;
1317
import org.testng.annotations.DataProvider;
1418
import org.testng.annotations.Test;
1519
import java.net.URL;
1620
import java.time.Duration;
21+
import java.util.HashMap;
1722

1823

19-
public class MashReqAppPerf {
24+
public class MashReqAppPerf implements ITest {
2025

21-
public AndroidDriver driver;
26+
private static ThreadLocal<AndroidDriver> driver = new ThreadLocal<>();
27+
private int data;
2228

23-
@DataProvider(name = "testData", parallel = true)
24-
public Object[][] createTestData() {
25-
Object[][] data = new Object[50][1];
26-
for (int i = 0; i < 50; i++) {
27-
data[i][0] = i + 1; // Numbers 1 to 50
28-
}
29-
return data;
29+
private String testName;
30+
31+
public AndroidDriver getDriver() {
32+
return driver.get();
33+
}
34+
35+
public MashReqAppPerf(int data)
36+
{
37+
this.data=data;
38+
this.testName = "MashReq API limit test "+data;
3039
}
3140

3241

42+
3343
@BeforeMethod(alwaysRun=true)
3444
public void setUp() throws Exception {
45+
MutableCapabilities capabilities = new UiAutomator2Options();
46+
HashMap<String, Object> bstackOptions = new HashMap<String, Object>();
47+
bstackOptions.put("sessionName", testName);
48+
capabilities.setCapability("bstack:options", bstackOptions);
49+
50+
AndroidDriver driverInstance = new AndroidDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
51+
driver.set(driverInstance);
3552

36-
AppiumClientConfig clientConfig = AppiumClientConfig.defaultConfig()
37-
.baseUrl(new URL("http://localhost:4444/wd/hub"))
38-
.connectionTimeout(Duration.ofSeconds(180))
39-
.readTimeout(Duration.ofSeconds(300)); // Example: 300 seconds
4053

41-
MutableCapabilities capabilities = new UiAutomator2Options();
42-
capabilities.setCapability("platformName", "android");
43-
capabilities.setCapability("appium:platformVersion", "12.0");
44-
capabilities.setCapability("appium:deviceName", "Samsung Galaxy S22 Ultra");
45-
capabilities.setCapability("appium:app", "bs://9956628e64b1fe6243e24fafd2e3dec3b741a774");
46-
driver = new AndroidDriver(clientConfig,capabilities);
4754
}
4855

4956
//@Test(dataProvider = "testData")
5057
@Test
5158
public void testApp() throws Exception {
52-
int data=1;
59+
//int data=1;
5360
System.out.println("Test run "+ data);
54-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
61+
62+
WebDriverWait wait = new WebDriverWait(getDriver(), Duration.ofSeconds(30));
5563
WebElement searchElement = (WebElement) wait.until(
5664
ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia")));
5765

66+
JavascriptExecutor jse = (JavascriptExecutor) getDriver();
67+
68+
jse.executeScript("\"browserstack_executor\": {\"action\": \"setSessionName\", \"arguments\": {\"name\": \""+testName+"\"}}");
69+
5870
}
5971

6072
@AfterMethod(alwaysRun=true)
6173
public void tearDown() throws Exception {
62-
driver.quit();
74+
getDriver().quit();
75+
}
76+
77+
@Override
78+
public String getTestName() {
79+
return testName;
6380
}
6481
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.browserstack.perftest;
2+
3+
import org.testng.annotations.DataProvider;
4+
import org.testng.annotations.Factory;
5+
6+
7+
public class TestDataFactory {
8+
9+
@DataProvider(name = "testData", parallel = true)
10+
public Object[][] createTestData() {
11+
Object[][] data = new Object[50][1];
12+
for (int i = 0; i < 50; i++) {
13+
data[i][0] = i + 1; // Numbers 1 to 50
14+
}
15+
return data;
16+
}
17+
18+
@Factory(dataProvider = "testData")
19+
public Object[] createInstances(int data) {
20+
return new Object[] {
21+
new MashReqAppPerf(data)
22+
};
23+
}
24+
}

0 commit comments

Comments
 (0)