|
1 | 1 | package com.lambdatest;
|
2 | 2 |
|
3 |
| -import io.appium.java_client.AppiumDriver; |
4 |
| -import io.appium.java_client.MobileBy; |
5 |
| -//import org.junit.Test; |
6 |
| -import org.openqa.selenium.By; |
7 |
| -import org.openqa.selenium.remote.DesiredCapabilities; |
8 |
| -import org.openqa.selenium.support.ui.ExpectedConditions; |
9 |
| -import org.openqa.selenium.support.ui.WebDriverWait; |
10 |
| -import org.testng.ITestResult; |
11 |
| -import org.testng.annotations.AfterTest; |
12 |
| -import org.testng.annotations.BeforeTest; |
13 |
| -import org.testng.annotations.Test; |
14 |
| - |
| 3 | +import java.lang.reflect.Method; |
15 | 4 | import java.net.MalformedURLException;
|
16 | 5 | import java.net.URL;
|
17 | 6 | import java.util.HashMap;
|
| 7 | +import org.openqa.selenium.By; |
| 8 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 9 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 10 | +import org.testng.Assert; |
| 11 | +import org.testng.ITestContext; |
| 12 | +import org.testng.annotations.AfterMethod; |
| 13 | +import org.testng.annotations.BeforeMethod; |
| 14 | +import org.testng.annotations.Test; |
18 | 15 |
|
19 | 16 | public class sel4 {
|
20 |
| - String username = "deepanshulambdatest"; |
21 |
| - String authkey = "f8xr8eV7hpJJixO6sbVmPazAH4C8VoAUhEANPjikayLTXNlJKs"; |
22 |
| - public static AppiumDriver driver = null; |
23 |
| - public String gridURL = "@mobile-hub.lambdatest.com/wd/hub"; |
24 |
| - public String status = "passed"; |
25 |
| - @BeforeTest |
26 |
| - public void setUp() throws Exception { |
27 | 17 |
|
| 18 | + private RemoteWebDriver driver; |
| 19 | + private String Status = "failed"; |
| 20 | + |
| 21 | + @BeforeMethod |
| 22 | + public void setup(Method m, ITestContext ctx) throws MalformedURLException { |
| 23 | + String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); |
| 24 | + String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); |
| 25 | + ; |
| 26 | + String hub = "@hub.lambdatest.com/wd/hub"; |
28 | 27 |
|
29 |
| - DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 28 | + DesiredCapabilities capabilities = new DesiredCapabilities(); |
30 | 29 | HashMap<String, Object> ltOptions = new HashMap<String, Object>();
|
31 | 30 | ltOptions.put("w3c", true);
|
32 |
| - ltOptions.put("platformName", "ios"); |
33 |
| - ltOptions.put("deviceName", "iPhone 14"); |
34 |
| - ltOptions.put("platformVersion", "16"); |
35 |
| - ltOptions.put("isRealMobile", true); |
36 |
| - ltOptions.put("app", "lt://APP1016045801684404228061622"); |
| 31 | + ltOptions.put("browserName", "Chrome"); |
| 32 | + ltOptions.put("platformName", "Windows 11"); |
| 33 | + ltOptions.put("browserVersion", "110"); |
37 | 34 | capabilities.setCapability("lt:options", ltOptions);
|
38 | 35 |
|
39 | 36 |
|
40 | 37 |
|
41 |
| - try |
42 |
| - { |
43 |
| - driver = new AppiumDriver(new URL("https://" + username + ":" + authkey + gridURL), capabilities); |
44 |
| - Thread.sleep(5000); |
45 |
| - |
46 |
| - } |
47 |
| - catch (MalformedURLException e) |
48 |
| - { |
49 |
| - System.out.println("Invalid grid URL"); |
50 |
| - } catch (Exception e) |
51 |
| - { |
52 |
| - System.out.println(e.getMessage()); |
53 |
| - } |
54 |
| - |
| 38 | + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), capabilities); |
55 | 39 | }
|
56 | 40 |
|
57 | 41 | @Test
|
58 |
| - public void testSimple() throws Exception |
59 |
| - { |
60 |
| - try |
61 |
| - { |
62 |
| - driver.findElement(By.xpath("//XCUIElementTypeButton[@name=\"navigation_account\"]")).click(); |
63 |
| - Thread.sleep(5000); |
64 |
| - |
65 |
| - driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"et_email\"]")).sendKeys("01100000110"); |
66 |
| - Thread.sleep(5000); |
67 |
| - |
68 |
| - driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@name=\"et_password\"]\n")).sendKeys("Test@123"); |
69 |
| - Thread.sleep(5000); |
70 |
| - |
71 |
| - driver.findElement(By.xpath("\t\n" + "//XCUIElementTypeButton[@name=\"mb_continue\"]")).click(); |
72 |
| - Thread.sleep(20000); |
73 |
| - |
74 |
| - driver.findElement(By.xpath("//XCUIElementTypeButton[@name=\"navigation_account\"]")).click(); |
75 |
| - Thread.sleep(20000); |
76 |
| - |
77 |
| - status="passed"; |
78 |
| - } |
79 |
| - catch (Exception e) |
80 |
| - { |
81 |
| - System.out.println(e.getMessage()); |
82 |
| - status="failed"; |
83 |
| - } |
| 42 | + public void basicTest() throws InterruptedException { |
| 43 | + String spanText; |
| 44 | + System.out.println("Loading Url"); |
| 45 | + Thread.sleep(100); |
| 46 | + driver.get("https://lambdatest.github.io/sample-todo-app/"); |
| 47 | + |
| 48 | + System.out.println("Checking Box"); |
| 49 | + driver.findElement(By.name("li1")).click(); |
| 50 | + |
| 51 | + System.out.println("Checking Another Box"); |
| 52 | + driver.findElement(By.name("li2")).click(); |
| 53 | + |
| 54 | + System.out.println("Checking Box"); |
| 55 | + driver.findElement(By.name("li3")).click(); |
| 56 | + |
| 57 | + System.out.println("Checking Another Box"); |
| 58 | + driver.findElement(By.name("li4")).click(); |
| 59 | + |
| 60 | + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6"); |
| 61 | + driver.findElement(By.id("addbutton")).click(); |
| 62 | + |
| 63 | + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7"); |
| 64 | + driver.findElement(By.id("addbutton")).click(); |
| 65 | + |
| 66 | + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); |
| 67 | + driver.findElement(By.id("addbutton")).click(); |
| 68 | + |
| 69 | + System.out.println("Checking Another Box"); |
| 70 | + driver.findElement(By.name("li1")).click(); |
| 71 | + |
| 72 | + System.out.println("Checking Another Box"); |
| 73 | + driver.findElement(By.name("li3")).click(); |
| 74 | + |
| 75 | + System.out.println("Checking Another Box"); |
| 76 | + driver.findElement(By.name("li7")).click(); |
| 77 | + |
| 78 | + System.out.println("Checking Another Box"); |
| 79 | + driver.findElement(By.name("li8")).click(); |
| 80 | + |
| 81 | + System.out.println("Entering Text"); |
| 82 | + driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); |
| 83 | + |
| 84 | + driver.findElement(By.id("addbutton")).click(); |
| 85 | + |
| 86 | + System.out.println("Checking Another Box"); |
| 87 | + driver.findElement(By.name("li9")).click(); |
| 88 | + |
| 89 | + // Let's also assert that the todo we added is present in the list. |
| 90 | + |
| 91 | + spanText = driver.findElementByXPath("/html/body/div/div/div/ul/li[9]/span").getText(); |
| 92 | + Assert.assertEquals("Get Taste of Lambda and Stick to It", spanText); |
| 93 | + Status = "passed"; |
| 94 | + Thread.sleep(800); |
| 95 | + |
| 96 | + System.out.println("TestFinished"); |
| 97 | + |
84 | 98 | }
|
85 |
| - @AfterTest |
86 |
| - public void tearDown(ITestResult result) throws Exception |
87 |
| - { |
88 |
| - if (driver != null) |
89 |
| - { |
90 |
| - driver.executeScript("lambda-status=" + status); |
91 |
| - driver.quit(); |
92 |
| - } |
| 99 | + |
| 100 | + @AfterMethod |
| 101 | + public void tearDown() { |
| 102 | + driver.executeScript("lambda-status=" + Status); |
| 103 | + driver.quit(); |
93 | 104 | }
|
| 105 | + |
94 | 106 | }
|
0 commit comments