|
4 | 4 | import io.appium.java_client.AppiumClientConfig; |
5 | 5 | import io.appium.java_client.android.AndroidDriver; |
6 | 6 | import io.appium.java_client.android.options.UiAutomator2Options; |
| 7 | +import org.openqa.selenium.JavascriptExecutor; |
7 | 8 | import org.openqa.selenium.MutableCapabilities; |
8 | 9 | import org.openqa.selenium.WebElement; |
9 | 10 | import org.openqa.selenium.support.ui.ExpectedConditions; |
10 | 11 | import org.openqa.selenium.support.ui.WebDriverWait; |
| 12 | +import org.testng.ITest; |
| 13 | +import org.testng.ITestContext; |
| 14 | +import org.testng.ITestNGMethod; |
11 | 15 | import org.testng.annotations.AfterMethod; |
12 | 16 | import org.testng.annotations.BeforeMethod; |
13 | 17 | import org.testng.annotations.DataProvider; |
14 | 18 | import org.testng.annotations.Test; |
15 | 19 | import java.net.URL; |
16 | 20 | import java.time.Duration; |
| 21 | +import java.util.HashMap; |
17 | 22 |
|
18 | 23 |
|
19 | | -public class MashReqAppPerf { |
| 24 | +public class MashReqAppPerf implements ITest { |
20 | 25 |
|
21 | | - public AndroidDriver driver; |
| 26 | + private static ThreadLocal<AndroidDriver> driver = new ThreadLocal<>(); |
| 27 | + private int data; |
22 | 28 |
|
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; |
30 | 39 | } |
31 | 40 |
|
32 | 41 |
|
| 42 | + |
33 | 43 | @BeforeMethod(alwaysRun=true) |
34 | 44 | 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); |
35 | 52 |
|
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 |
40 | 53 |
|
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); |
47 | 54 | } |
48 | 55 |
|
49 | 56 | //@Test(dataProvider = "testData") |
50 | 57 | @Test |
51 | 58 | public void testApp() throws Exception { |
52 | | - int data=1; |
| 59 | + //int data=1; |
53 | 60 | 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)); |
55 | 63 | WebElement searchElement = (WebElement) wait.until( |
56 | 64 | ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia"))); |
57 | 65 |
|
| 66 | + JavascriptExecutor jse = (JavascriptExecutor) getDriver(); |
| 67 | + |
| 68 | + jse.executeScript("\"browserstack_executor\": {\"action\": \"setSessionName\", \"arguments\": {\"name\": \""+testName+"\"}}"); |
| 69 | + |
58 | 70 | } |
59 | 71 |
|
60 | 72 | @AfterMethod(alwaysRun=true) |
61 | 73 | public void tearDown() throws Exception { |
62 | | - driver.quit(); |
| 74 | + getDriver().quit(); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String getTestName() { |
| 79 | + return testName; |
63 | 80 | } |
64 | 81 | } |
0 commit comments