From 338cc5e398a04df1d147f9e46a60a13b1a7826ca Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:45:30 +0530 Subject: [PATCH 1/8] Update ChromeDriverTest.java --- src/test/java/org/movoto/selenium/example/ChromeDriverTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java index 0fe8b02..0d3d50e 100644 --- a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java +++ b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java @@ -35,7 +35,7 @@ public void prepare() { "webdriver.chrome.driver", "webdriver/chromedriver"); - testUrl = "https://leftstick.github.io/"; + testUrl = "https://www.youtube.com/"; // Create a new instance of the Chrome driver // Notice that the remainder of the code relies on the interface, From d344646979d1b61ef3a3eda5634eaff79bbaac18 Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:45:55 +0530 Subject: [PATCH 2/8] Update FirefoxTest.java --- src/test/java/org/movoto/selenium/example/FirefoxTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/movoto/selenium/example/FirefoxTest.java b/src/test/java/org/movoto/selenium/example/FirefoxTest.java index 761b7aa..ec215ab 100644 --- a/src/test/java/org/movoto/selenium/example/FirefoxTest.java +++ b/src/test/java/org/movoto/selenium/example/FirefoxTest.java @@ -30,7 +30,7 @@ public class FirefoxTest { @Before public void prepare() { - testUrl = "https://leftstick.github.io/"; + testUrl = "https://www.youtube.com/"; System.setProperty("webdriver.gecko.driver","webdriver/geckodriver"); From 705db4918a4c08f2a09543af4cdd60246b6bcf0c Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:46:11 +0530 Subject: [PATCH 3/8] Delete src/test/java/org/movoto/selenium/example/SafariTest.java --- .../movoto/selenium/example/SafariTest.java | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 src/test/java/org/movoto/selenium/example/SafariTest.java diff --git a/src/test/java/org/movoto/selenium/example/SafariTest.java b/src/test/java/org/movoto/selenium/example/SafariTest.java deleted file mode 100644 index e6405e1..0000000 --- a/src/test/java/org/movoto/selenium/example/SafariTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.movoto.selenium.example; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.openqa.selenium.*; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.interactions.Mouse; -import org.openqa.selenium.safari.SafariDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertTrue; - -/** - * Created by haozuo on 3/22/16. - */ -public class SafariTest { - - private String testUrl; - private WebDriver driver; - - @Before - public void prepare() { - - testUrl = "https://leftstick.github.io/"; - - driver = new SafariDriver(); - driver.manage().window().maximize(); - driver.get(testUrl); - } - - @Test - public void testTitle() throws IOException { - - // Find elements by attribute lang="READ_MORE_BTN" - List elements = driver - .findElements(By.cssSelector("[lang=\"READ_MORE_BTN\"]")); - - //Click the selected button - elements.get(0).click(); - - - assertTrue("The page title should be chagned as expected", - (new WebDriverWait(driver, 5)) - .until(new ExpectedCondition() { - public Boolean apply(WebDriver d) { - return d.getTitle().equals("我眼中软件工程人员该有的常识"); - } - }) - ); - - } - - @After - public void teardown() throws IOException { - driver.quit(); - } - -} From 9bd4411b82b566e62ef7e419d1ba520e76bd16f0 Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:04:40 +0530 Subject: [PATCH 4/8] Update ChromeDriverTest.java --- .../selenium/example/ChromeDriverTest.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java index 0d3d50e..84a4356 100644 --- a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java +++ b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java @@ -1,28 +1,18 @@ -package org.movoto.selenium.example; - import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.firefox.MarionetteDriver; -import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; import java.io.IOException; import java.util.List; -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertTrue; -/** - * Created by haozuo on 3/22/16. - */ public class ChromeDriverTest { private String testUrl; @@ -30,39 +20,34 @@ public class ChromeDriverTest { @Before public void prepare() { - //setup chromedriver + // Set up ChromeDriver System.setProperty( "webdriver.chrome.driver", - "webdriver/chromedriver"); + "C:/path/to/chromedriver.exe"); // Use the absolute path testUrl = "https://www.youtube.com/"; - // Create a new instance of the Chrome driver - // Notice that the remainder of the code relies on the interface, - // not the implementation. + // Initialize ChromeDriver driver = new ChromeDriver(); - //maximize window + // Maximize window driver.manage().window().maximize(); - // And now use this to visit myBlog - // Alternatively the same thing can be done like this - // driver.navigate().to(testUrl); + // Navigate to test URL driver.get(testUrl); } @Test public void testTitle() throws IOException { - // Find elements by attribute lang="READ_MORE_BTN" List elements = driver .findElements(By.cssSelector("[lang=\"READ_MORE_BTN\"]")); - //Click the selected button + // Click the selected button elements.get(0).click(); - - assertTrue("The page title should be chagned as expected", + // Wait for the page title to change and assert it + assertTrue("The page title should be changed as expected", (new WebDriverWait(driver, 5)) .until(new ExpectedCondition() { public Boolean apply(WebDriver d) { @@ -70,12 +55,13 @@ public Boolean apply(WebDriver d) { } }) ); - } @After public void teardown() throws IOException { - driver.quit(); + // Check if driver is not null before quitting + if (driver != null) { + driver.quit(); + } } - } From ea706cb6d54031fbeff5f82c6d0fe3dd82a347d3 Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:04:54 +0530 Subject: [PATCH 5/8] Delete src/test/java/org/movoto/selenium/example/FirefoxTest.java --- .../movoto/selenium/example/FirefoxTest.java | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/test/java/org/movoto/selenium/example/FirefoxTest.java diff --git a/src/test/java/org/movoto/selenium/example/FirefoxTest.java b/src/test/java/org/movoto/selenium/example/FirefoxTest.java deleted file mode 100644 index ec215ab..0000000 --- a/src/test/java/org/movoto/selenium/example/FirefoxTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.movoto.selenium.example; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.htmlunit.HtmlUnitDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertTrue; - -/** - * Created by haozuo on 3/23/16. - */ -public class FirefoxTest { - - private String testUrl; - private WebDriver driver; - - @Before - public void prepare() { - - testUrl = "https://www.youtube.com/"; - - System.setProperty("webdriver.gecko.driver","webdriver/geckodriver"); - - // Create a new instance of the Chrome driver - // Notice that the remainder of the code relies on the interface, - // not the implementation. - driver = new FirefoxDriver(); - - // And now use this to visit myBlog - // Alternatively the same thing can be done like this - // driver.navigate().to(testUrl); - driver.get(testUrl); - } - - @Test - public void testTitle() throws IOException { - - // Find elements by attribute lang="READ_MORE_BTN" - List elements = driver - .findElements(By.cssSelector("[lang=\"READ_MORE_BTN\"]")); - - //Click the selected button - elements.get(0).click(); - - - assertTrue("The page title should be chagned as expected", - (new WebDriverWait(driver, 3)) - .until(new ExpectedCondition() { - public Boolean apply(WebDriver d) { - return d.getTitle().equals("我眼中软件工程人员该有的常识"); - } - }) - ); - } - - @After - public void teardown() throws IOException { - driver.quit(); - } - -} From 258390c09c64bec51bba634a5bc7486ee1e495b0 Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:07:39 +0530 Subject: [PATCH 6/8] Update ChromeDriverTest.java --- .../java/org/movoto/selenium/example/ChromeDriverTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java index 84a4356..515cb08 100644 --- a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java +++ b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java @@ -20,10 +20,10 @@ public class ChromeDriverTest { @Before public void prepare() { - // Set up ChromeDriver + //setup chromedriver System.setProperty( "webdriver.chrome.driver", - "C:/path/to/chromedriver.exe"); // Use the absolute path + "webdriver/chromedriver"); testUrl = "https://www.youtube.com/"; From 808f00cca99d55447588f54c70dbe1df20a3bdd9 Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:18:39 +0530 Subject: [PATCH 7/8] Update pom.xml --- pom.xml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 32c4583..778ba6d 100644 --- a/pom.xml +++ b/pom.xml @@ -1 +1,48 @@ - 4.0.0 com.movoto.tests selenium-example 1.0-SNAPSHOT junit junit 4.12 test org.seleniumhq.selenium selenium-java 3.0.1 org.seleniumhq.selenium selenium-chrome-driver 3.0.1 org.seleniumhq.selenium htmlunit-driver 2.23.2 org.seleniumhq.selenium selenium-firefox-driver 3.0.1 \ No newline at end of file + + + 4.0.0 + + com.movoto.tests + selenium-example + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + test + + + + org.seleniumhq.selenium + selenium-java + 4.11.0 + + + + org.seleniumhq.selenium + selenium-chrome-driver + 4.11.0 + + + + org.seleniumhq.selenium + htmlunit-driver + 2.70.0 + + + + org.seleniumhq.selenium + selenium-firefox-driver + 4.11.0 + + + + + + + From 7010f5710dbc538c2352879d8b95de2c939cdf28 Mon Sep 17 00:00:00 2001 From: Aditya <141542441+Adityacodesinpython@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:20:54 +0530 Subject: [PATCH 8/8] Update ChromeDriverTest.java --- .../selenium/example/ChromeDriverTest.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java index 515cb08..7650cb4 100644 --- a/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java +++ b/src/test/java/org/movoto/selenium/example/ChromeDriverTest.java @@ -37,25 +37,26 @@ public void prepare() { driver.get(testUrl); } - @Test - public void testTitle() throws IOException { - // Find elements by attribute lang="READ_MORE_BTN" - List elements = driver - .findElements(By.cssSelector("[lang=\"READ_MORE_BTN\"]")); + @Test +public void testTitle() throws IOException { + // Find elements by attribute lang="READ_MORE_BTN" + List elements = driver + .findElements(By.cssSelector("[lang=\"READ_MORE_BTN\"]")); - // Click the selected button - elements.get(0).click(); + // Click the selected button + elements.get(0).click(); + + // Wait for the page title to change and assert it + assertTrue("The page title should be changed as expected", + (new WebDriverWait(driver, java.time.Duration.ofSeconds(5))) + .until(new ExpectedCondition() { + public Boolean apply(WebDriver d) { + return d.getTitle().equals("我眼中软件工程人员该有的常识"); + } + }) + ); +} - // Wait for the page title to change and assert it - assertTrue("The page title should be changed as expected", - (new WebDriverWait(driver, 5)) - .until(new ExpectedCondition() { - public Boolean apply(WebDriver d) { - return d.getTitle().equals("我眼中软件工程人员该有的常识"); - } - }) - ); - } @After public void teardown() throws IOException {