From 1218bf8240f68584671018e8716192810237d93d Mon Sep 17 00:00:00 2001 From: Sirajuddin Khan Date: Thu, 4 Jan 2024 11:42:57 +0000 Subject: [PATCH 1/5] autohealing Demo --- autoheal.xml | 15 +++ .../java/com/lambdatest/AutoHealingDemo.java | 122 ++++++++++++++++++ testng_win.xml | 15 +++ 3 files changed, 152 insertions(+) create mode 100644 autoheal.xml create mode 100644 src/test/java/com/lambdatest/AutoHealingDemo.java create mode 100644 testng_win.xml diff --git a/autoheal.xml b/autoheal.xml new file mode 100644 index 0000000..adb9a04 --- /dev/null +++ b/autoheal.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/lambdatest/AutoHealingDemo.java b/src/test/java/com/lambdatest/AutoHealingDemo.java new file mode 100644 index 0000000..7dd9273 --- /dev/null +++ b/src/test/java/com/lambdatest/AutoHealingDemo.java @@ -0,0 +1,122 @@ +package com.lambdatest; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.*; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; + +import java.lang.reflect.Method; +import org.testng.Assert; +import org.testng.ITestContext; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class AutoHealingDemo +{ + RemoteWebDriver driver = null; + public static String status = "passed"; + public static String username = System.getenv("LT_USERNAME"); + public static String access_key = System.getenv("LT_ACCESS_KEY"); + + + @BeforeMethod + @Parameters(value={"browser","version","platform", "resolution"}) + public void testSetUp(String browser, String version, String platform, String resolution,Method m, ITestContext ctx) throws Exception + { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("build", "Demonstration of the AutoHeal"); + // capabilities.setCapability("platform", "Windows 10")); + capabilities.setCapability("browserName", browser); + capabilities.setCapability("name",m.getName() ); + // capabilities.setCapability("version", version); + + // capabilities.setCapability("tunnel",false); + // capabilities.setCapability("network",true); + // capabilities.setCapability("console",true); + capabilities.setCapability("visual",true); + capabilities.setCapability("autoHeal", true); + + try + { + driver = new RemoteWebDriver(new URL("https://" + username + ":" + access_key + "@hub.lambdatest.com/wd/hub"), capabilities); + } + catch (MalformedURLException e) + { + System.out.println("Invalid grid URL"); + } + System.out.println("Started session"); + } + + @Test() + public void autoHealBaseTestWithoutChangedDOM() throws InterruptedException + { + + try { + + driver.get("https://www.lambdatest.com/selenium-playground/auto-healing"); + Thread.sleep(5000); + + WebElement changedom = driver.findElementByXPath("//*[contains(text(), 'Change DOM ID')]"); + // changedom.click(); //Uncomment this line in the 2nd test run for the autoheal to work. + + WebElement username = driver.findElementById("username"); + username.sendKeys("test@gmail.com"); + + WebElement password = driver.findElementById("password"); + password.sendKeys("password"); + + WebElement login = driver.findElementByXPath("//*[contains(text(), 'Submit')]"); + login.click(); + + } catch (Exception e) { + status = "failed"; + } + } + + @Test() + public void autoHealedWithChangedDOM() throws InterruptedException + { + + try { + + driver.get("https://www.lambdatest.com/selenium-playground/auto-healing"); + Thread.sleep(5000); + + WebElement changedom = driver.findElementByXPath("//*[contains(text(), 'Change DOM ID')]"); + changedom.click(); //Uncomment this line in the 2nd test run for the autoheal to work. + + WebElement username = driver.findElementById("username"); + username.sendKeys("test@gmail.com"); + + WebElement password = driver.findElementById("password"); + password.sendKeys("password"); + + WebElement login = driver.findElementByXPath("//*[contains(text(), 'Submit')]"); + login.click(); + + } catch (Exception e) { + status = "failed"; + } + + + + } + + @AfterMethod + public void tearDown() + { + if (driver != null) + { + ((JavascriptExecutor) driver).executeScript("lambda-status=" + status); + driver.quit(); + } + } +} \ No newline at end of file diff --git a/testng_win.xml b/testng_win.xml new file mode 100644 index 0000000..adb9a04 --- /dev/null +++ b/testng_win.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file From e031828921193702158cc20e0f198ecdc8b39e07 Mon Sep 17 00:00:00 2001 From: Sirajuddin Khan Date: Tue, 27 Feb 2024 09:36:38 +0000 Subject: [PATCH 2/5] StepContext Added --- .../java/com/lambdatest/AutoHealingDemo.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/lambdatest/AutoHealingDemo.java b/src/test/java/com/lambdatest/AutoHealingDemo.java index 7dd9273..fecf69f 100644 --- a/src/test/java/com/lambdatest/AutoHealingDemo.java +++ b/src/test/java/com/lambdatest/AutoHealingDemo.java @@ -1,17 +1,12 @@ package com.lambdatest; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.*; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.*; import java.net.MalformedURLException; import java.net.URL; -import java.time.Duration; - import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -63,6 +58,8 @@ public void autoHealBaseTestWithoutChangedDOM() throws InterruptedException driver.get("https://www.lambdatest.com/selenium-playground/auto-healing"); Thread.sleep(5000); + + driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"AutoHealWithoutDomChanged-Login Case\", \"level\": \"info\"}}"); WebElement changedom = driver.findElementByXPath("//*[contains(text(), 'Change DOM ID')]"); // changedom.click(); //Uncomment this line in the 2nd test run for the autoheal to work. @@ -81,7 +78,7 @@ public void autoHealBaseTestWithoutChangedDOM() throws InterruptedException } } - @Test() + @Test() public void autoHealedWithChangedDOM() throws InterruptedException { @@ -89,9 +86,11 @@ public void autoHealedWithChangedDOM() throws InterruptedException driver.get("https://www.lambdatest.com/selenium-playground/auto-healing"); Thread.sleep(5000); - + + driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"AutoHealDomChanged-Login Case\", \"level\": \"info\"}}"); + WebElement changedom = driver.findElementByXPath("//*[contains(text(), 'Change DOM ID')]"); - changedom.click(); //Uncomment this line in the 2nd test run for the autoheal to work. + changedom.click(); WebElement username = driver.findElementById("username"); username.sendKeys("test@gmail.com"); @@ -114,8 +113,8 @@ public void autoHealedWithChangedDOM() throws InterruptedException public void tearDown() { if (driver != null) - { - ((JavascriptExecutor) driver).executeScript("lambda-status=" + status); + { driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Completed-Login Case - Closing Browser\", \"level\": \"info\"}}"); + driver.executeScript("lambda-status=" + status); driver.quit(); } } From 207762b94888758fffbec852f1d9d1a3afd902ed Mon Sep 17 00:00:00 2001 From: Sirajuddin Khan Date: Wed, 13 Mar 2024 12:23:45 +0000 Subject: [PATCH 3/5] gitpod yml update --- .gitpod.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitpod.yml b/.gitpod.yml index 2f1526e..a8395ef 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -5,5 +5,5 @@ ports: # List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/ tasks: - - init: mvn install -Dsuite=parallel.xml # runs during prebuild + - init: mvn install -Dsuite=autoheal.xml # runs during prebuild command: echo 'Please check your test on https://automation.lambdatest.com/' From ce3e1c2a2813b68445adf24bc48134b0702244eb Mon Sep 17 00:00:00 2001 From: Sirajuddin Khan Date: Wed, 13 Mar 2024 13:11:13 +0000 Subject: [PATCH 4/5] added failed case --- .../java/com/lambdatest/AutoHealingDemo.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/lambdatest/AutoHealingDemo.java b/src/test/java/com/lambdatest/AutoHealingDemo.java index fecf69f..de1c829 100644 --- a/src/test/java/com/lambdatest/AutoHealingDemo.java +++ b/src/test/java/com/lambdatest/AutoHealingDemo.java @@ -37,7 +37,7 @@ public void testSetUp(String browser, String version, String platform, String re // capabilities.setCapability("network",true); // capabilities.setCapability("console",true); capabilities.setCapability("visual",true); - capabilities.setCapability("autoHeal", true); + capabilities.setCapability("autoHeal", System.getProperty("autoheal", "true")); try { @@ -72,9 +72,42 @@ public void autoHealBaseTestWithoutChangedDOM() throws InterruptedException WebElement login = driver.findElementByXPath("//*[contains(text(), 'Submit')]"); login.click(); + System.setProperty("autoheal", "false"); } catch (Exception e) { status = "failed"; + System.setProperty("autoheal", "false"); + } + } + + @Test() + public void autoHealFalseWithChangedDOM() throws InterruptedException + { + + try { + + + driver.get("https://www.lambdatest.com/selenium-playground/auto-healing"); + Thread.sleep(5000); + + driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"AutoHealWithoutDomChanged-Login Case\", \"level\": \"info\"}}"); + + WebElement changedom = driver.findElementByXPath("//*[contains(text(), 'Change DOM ID')]"); + changedom.click(); //Uncomment this line in the 2nd test run for the autoheal to work. + + WebElement username = driver.findElementById("username"); + username.sendKeys("test@gmail.com"); + + WebElement password = driver.findElementById("password"); + password.sendKeys("password"); + + WebElement login = driver.findElementByXPath("//*[contains(text(), 'Submit')]"); + login.click(); + System.setProperty("autoheal", "true"); + + } catch (Exception e) { + status = "failed"; + System.setProperty("autoheal", "true"); } } @@ -100,6 +133,7 @@ public void autoHealedWithChangedDOM() throws InterruptedException WebElement login = driver.findElementByXPath("//*[contains(text(), 'Submit')]"); login.click(); + status="passed"; } catch (Exception e) { status = "failed"; From 23572ec50f5a887585bb68cceebb3cdd3e6d25ad Mon Sep 17 00:00:00 2001 From: Sirajuddin Khan Date: Mon, 12 Aug 2024 13:10:43 +0000 Subject: [PATCH 5/5] readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0e3c77..4e0734e 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,8 @@ Make sure you have your LambdaTest credentials with you to run test automation s ```java DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "chrome"); - capabilities.setCapability("version", "70.0"); - capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one + capabilities.setCapability("version", "latest"); + capabilities.setCapability("platform", "Windows 10"); // If this cap isn't specified, it will just get the any available one capabilities.setCapability("build", "LambdaTestSampleApp"); capabilities.setCapability("name", "LambdaTestJavaSample"); ```