Compare commits
2 Commits
daa6758940
...
31e62b925a
| Author | SHA1 | Date | |
|---|---|---|---|
| 31e62b925a | |||
| fd65bf087c |
Generated
+1
-1
@@ -9,6 +9,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
<output url="file://$PROJECT_DIR$/../BrushUpJava" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<WebElement> itemsName = driver.findElements(By.cssSelector("h4[class$='product-name']"));
|
||||
List<String> listOfItems = Arrays.asList(items);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package zacksolutions;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
/**
|
||||
* SwitchWin
|
||||
*/
|
||||
public class SwitchWin {
|
||||
|
||||
public static WebDriver driver;
|
||||
public static String email = "";
|
||||
|
||||
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://rahulshettyacademy.com/loginpagePractise/#";
|
||||
driver.get(url);
|
||||
try {
|
||||
loginPage();
|
||||
userInput();
|
||||
} finally {
|
||||
Thread.sleep(6000);
|
||||
driver.quit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loginPage() throws InterruptedException {
|
||||
driver.findElement(By.cssSelector(".blinkingText")).click();
|
||||
Set<String> tabs = driver.getWindowHandles();
|
||||
Iterator<String> it = tabs.iterator();
|
||||
String parentTab = it.next();
|
||||
String childTab = it.next();
|
||||
driver.switchTo().window(childTab);
|
||||
String []phrase = driver.findElement(By.cssSelector(".im-para.red")).getText().split(" ");
|
||||
for (int i = 0; i < phrase.length; i++) {
|
||||
if(phrase[i].contains("@")){
|
||||
email = phrase[i].trim();
|
||||
}
|
||||
}
|
||||
System.out.println("Please use the followoing email: " + email);
|
||||
driver.switchTo().window(parentTab);
|
||||
}
|
||||
public static void userInput() throws InterruptedException {
|
||||
driver.findElement(By.cssSelector("#username")).sendKeys("rahulshettyacademy");
|
||||
driver.findElement(By.cssSelector("#password")).sendKeys("learning");
|
||||
driver.findElement(By.xpath("//label[2]//span[2]")).click();
|
||||
driver.findElement(By.cssSelector(".btn.btn-success")).click();
|
||||
driver.findElement(By.xpath("//input[@id='terms']")).click();
|
||||
driver.findElement((By.cssSelector(".btn.btn-info.btn-md"))).click();
|
||||
System.out.println(driver.getTitle());
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user