diff --git a/.idea/misc.xml b/.idea/misc.xml
index 82dbec8..3794b06 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -9,6 +9,6 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/zacksolutions/Ajax.java b/src/main/java/zacksolutions/Ajax.java
new file mode 100644
index 0000000..03ca260
--- /dev/null
+++ b/src/main/java/zacksolutions/Ajax.java
@@ -0,0 +1,48 @@
+package zacksolutions;
+
+import java.time.Duration;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+/**
+ * Ajax
+ */
+public class Ajax {
+
+ public static WebDriver driver;
+ public static String hoverText;
+
+ public static void main(String[] args) throws InterruptedException {
+
+ Initialize();
+ }
+
+ public static void Initialize() throws InterruptedException {
+ System.setProperty("web-driver.gecko.driver", "user.dir" + "LearnSelenium/DemoProject/drivers/geckodriver");
+ driver = new FirefoxDriver();
+ driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
+ String url = "https://www.amazon.com/";
+ driver.get(url);
+ try {
+ Actionz();
+ } finally {
+ driver.close();
+ }
+ }
+
+ public static void Actionz() {
+ Actions actions = new Actions(driver);
+ WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
+ wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nav-link-accountList")));
+ WebElement hover = driver.findElement(By.cssSelector("#nav-link-accountList"));
+ actions.moveToElement(hover);
+ hoverText = driver.findElement(By.cssSelector(".sc-ktJbId.bSNqcv")).getText();
+ System.out.println(hoverText);
+ }
+}
diff --git a/src/main/java/zacksolutions/AmazonQuestion.java b/src/main/java/zacksolutions/AmazonQuestion.java
index 3dece9d..a1f09f3 100644
--- a/src/main/java/zacksolutions/AmazonQuestion.java
+++ b/src/main/java/zacksolutions/AmazonQuestion.java
@@ -4,8 +4,8 @@ import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.interactions.Actions;
-import java.lang.reflect.Array;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
@@ -13,17 +13,21 @@ import java.util.List;
public class AmazonQuestion {
public static WebDriver driver;
public static String[] items = { "Brocolli", "Beetroot", "Beans", "Carrot", "Potato" };
+ public static String code = "";
- public static void main(String[] args) throws InterruptedException {
- System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
+ public static void main(String[] args) {
+ }
+
+ public static void Initialize() throws InterruptedException {
+
+ System.setProperty("web-driver.gecko.driver", "user.dir" + "LearnSelenium/DemoProject/drivers/geckodriver");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/seleniumPractise/";
driver.get(url);
- Thread.sleep(3000);
-
try {
getItems();
+ checkOut();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
@@ -32,6 +36,15 @@ public class AmazonQuestion {
}
+ public static void checkOut() {
+ driver.findElement(By.xpath("//a[@class='cart-icon']/img")).click();
+ driver.findElement(By.xpath("//div[@class='action-block']/button")).click();
+ driver.findElement(By.cssSelector(".promoCode")).sendKeys("rahulshettyacademy");
+ driver.findElement(By.cssSelector(".promoBtn")).click();
+ code = driver.findElement(By.cssSelector(".promoInfo")).getText();
+ System.out.println(code);
+ }
+
public static void getItems() throws InterruptedException {
List itemsName = driver.findElements(By.cssSelector("h4[class$='product-name']"));
List listOfItems = Arrays.asList(items);
diff --git a/src/main/java/zacksolutions/Locators.java b/src/main/java/zacksolutions/Locators.java
index 65e1a94..73327f8 100644
--- a/src/main/java/zacksolutions/Locators.java
+++ b/src/main/java/zacksolutions/Locators.java
@@ -15,18 +15,16 @@ public class Locators {
public static WebDriver driver;
public static void main(String[] args) throws InterruptedException, IOException {
- Locators lc = new Locators();
- lc.loginPage();
-
- getScreenShot(driver);
- }
-
- public void loginPage() throws InterruptedException {
System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/locatorspractice/";
driver.get(url);
+ loginPage();
+ getScreenShot(driver);
+ }
+
+ public static void loginPage() throws InterruptedException {
driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("input[name='inputPassword']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("button[type='submit']")).click();
diff --git a/src/test/java/zacksolutions/HoverTest.java b/src/test/java/zacksolutions/HoverTest.java
new file mode 100644
index 0000000..377f07f
--- /dev/null
+++ b/src/test/java/zacksolutions/HoverTest.java
@@ -0,0 +1,14 @@
+package zacksolutions;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HoverTest {
+ @Test
+ public void testHover() throws InterruptedException {
+ Ajax.Initialize();
+ Ajax.Actionz();
+ Assert.assertEquals("Who's shopping? Select a profile.", Ajax.hoverText);
+ System.out.println("Test confirmed");
+ }
+}
diff --git a/src/test/java/zacksolutions/TitleTest.java b/src/test/java/zacksolutions/TitleTest.java
index ec7c4d4..0628a06 100644
--- a/src/test/java/zacksolutions/TitleTest.java
+++ b/src/test/java/zacksolutions/TitleTest.java
@@ -4,10 +4,16 @@ import org.junit.Assert;
import org.junit.Test;
public class TitleTest {
- @Test
+ /* @Test
public void TestTitle() throws InterruptedException {
GuestBookWebPage.getTitle();
Assert.assertEquals("Guest Book", GuestBookWebPage.title);
System.out.println("The expected is: Guest Book and the actual is: " + GuestBookWebPage.title);
+ }*/
+ //@Test
+ public void checkOut() throws InterruptedException {
+ AmazonQuestion.Initialize();
+ Assert.assertEquals("Code applied ..!", AmazonQuestion.code);
+ System.out.println("CODE APPLIED SUCCESSFULLY!");
}
}