From 7f54698e6e9e4a238ab088edc7be7fa5728d6705 Mon Sep 17 00:00:00 2001 From: Sami Date: Fri, 8 Nov 2024 10:26:25 -0500 Subject: [PATCH] fix: CheckBoxDone --- .../SeleniumPractice/CheckBoxTest.java | 69 +++++++++++++++++++ testngCheckBox.xml | 18 +++++ 2 files changed, 87 insertions(+) create mode 100644 src/test/java/zacksolutions/SeleniumPractice/CheckBoxTest.java create mode 100644 testngCheckBox.xml diff --git a/src/test/java/zacksolutions/SeleniumPractice/CheckBoxTest.java b/src/test/java/zacksolutions/SeleniumPractice/CheckBoxTest.java new file mode 100644 index 0000000..fec728e --- /dev/null +++ b/src/test/java/zacksolutions/SeleniumPractice/CheckBoxTest.java @@ -0,0 +1,69 @@ +package zacksolutions.SeleniumPractice; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; + +public class CheckBoxTest { + + public WebDriver driver; + + @BeforeTest + @Parameters("Browser") + public void Setup(String browser) { + if (browser.equalsIgnoreCase("Chrome")) { +/* + ChromeOptions options = new ChromeOptions(); + try { + driver = new RemoteWebDriver(new URL("http://192.168.1.215:4444/wd/hub"), options); + } catch (MalformedURLException e) { + e.printStackTrace(); + } +*/ + System.getProperty("web-driver.chrome", "user.dir" + "/InterviewCodingQuestionsQA/Drivers/chromedriver"); + driver = new ChromeDriver(); + } if (browser.equalsIgnoreCase("FireFox")) { +/* + FirefoxOptions options = new FirefoxOptions(); + try { + driver = new RemoteWebDriver(new URL("http://192.168.1.215:4444/wd/hub"), options); + } catch (MalformedURLException e) { + // TODO: handle exception + e.printStackTrace(); + } +*/ + System.getProperty("web-driver.gecko", ("user.dir") + "InterviewCodingQuestionsQA/Drivers/geckodriver"); + driver = new FirefoxDriver(); + } + driver.get("https://demoqa.com/checkbox"); + //driver.manage().window().maximize(); + driver.manage().deleteAllCookies(); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); + } + + @Test + public void CheckBox() throws InterruptedException { + driver.findElement(By.cssSelector(".rct-icon.rct-icon-expand-all")).click(); + driver.findElement(By.xpath("//label[@for='tree-node-documents']//span[@class='rct-checkbox']")).click(); + driver.findElement(By.cssSelector(".rct-icon.rct-icon-collapse-all")).click(); + } + + @AfterTest + public void tearDown() throws InterruptedException { + Thread.sleep(5000); + driver.close(); + } +} diff --git a/testngCheckBox.xml b/testngCheckBox.xml new file mode 100644 index 0000000..c51e37c --- /dev/null +++ b/testngCheckBox.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file