Compare commits

...

3 Commits

Author SHA1 Message Date
Sami 5a3258e56f linksCounts
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 9s
2024-09-20 10:58:37 -04:00
Sami 31e62b925a SwitchTabsandWin
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 9s
2024-09-19 23:41:42 -04:00
Sami fd65bf087c sel_progress 2024-09-19 18:02:36 -04:00
8 changed files with 222 additions and 14 deletions
+1 -1
View File
@@ -9,6 +9,6 @@
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK"> <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> </component>
</project> </project>
+48
View File
@@ -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.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import java.lang.reflect.Array;
import java.time.Duration; import java.time.Duration;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -13,17 +13,21 @@ import java.util.List;
public class AmazonQuestion { public class AmazonQuestion {
public static WebDriver driver; public static WebDriver driver;
public static String[] items = { "Brocolli", "Beetroot", "Beans", "Carrot", "Potato" }; public static String[] items = { "Brocolli", "Beetroot", "Beans", "Carrot", "Potato" };
public static String code = "";
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) {
System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver"); }
public static void Initialize() throws InterruptedException {
System.setProperty("web-driver.gecko.driver", "user.dir" + "LearnSelenium/DemoProject/drivers/geckodriver");
driver = new FirefoxDriver(); driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/seleniumPractise/"; String url = "https://rahulshettyacademy.com/seleniumPractise/";
driver.get(url); driver.get(url);
Thread.sleep(3000);
try { try {
getItems(); getItems();
checkOut();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } 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 { public static void getItems() throws InterruptedException {
List<WebElement> itemsName = driver.findElements(By.cssSelector("h4[class$='product-name']")); List<WebElement> itemsName = driver.findElements(By.cssSelector("h4[class$='product-name']"));
List<String> listOfItems = Arrays.asList(items); List<String> listOfItems = Arrays.asList(items);
+5 -7
View File
@@ -15,18 +15,16 @@ public class Locators {
public static WebDriver driver; public static WebDriver driver;
public static void main(String[] args) throws InterruptedException, IOException { 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"); System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
driver = new FirefoxDriver(); driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/locatorspractice/"; String url = "https://rahulshettyacademy.com/locatorspractice/";
driver.get(url); 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[id='inputUsername']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("input[name='inputPassword']")).sendKeys("Zakaria"); driver.findElement(By.cssSelector("input[name='inputPassword']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("button[type='submit']")).click(); driver.findElement(By.cssSelector("button[type='submit']")).click();
+65
View File
@@ -0,0 +1,65 @@
package zacksolutions;
import java.time.Duration;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Scope {
public static WebDriver driver;
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://qaclickacademy.com/practice.php";
driver.get(url);
try {
linksCount();
} finally {
driver.quit();
}
}
public static void linksCount() throws InterruptedException {
//all the links in the home page
List<WebElement> linkC = driver.findElements(By.tagName("a"));
System.out.println("The full page links count is: " + linkC.size());
//all links in the pageFooter
WebElement footdriver = driver.findElement(By.xpath("//div[@id='gf-BIG']"));
List<WebElement> footLinks = footdriver.findElements(By.tagName("a"));
System.out.println("The footer pages links amount to: " + footLinks.size());
//all the links in the first column
WebElement columnDriver = footdriver.findElement(By.xpath("//div/table/tbody/tr/td[1]/ul"));
List<WebElement> columnLinks = columnDriver.findElements(By.tagName("a"));
System.out.println("The column links amount to: " + columnLinks.size());
//Open each link in the column
for(int i = 1; i < columnLinks.size(); i ++){
String clickON = Keys.chord(Keys.CONTROL, Keys.ENTER);
columnDriver.findElements(By.tagName("a")).get(i).sendKeys(clickON);
Thread.sleep(5000);
}
Set<String> tabs = driver.getWindowHandles();
Iterator<String> it = tabs.iterator();
while(it.hasNext()){
driver.switchTo().window(it.next());
System.out.println(driver.getTitle());
}
}
}
@@ -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");
}
}
+7 -1
View File
@@ -4,10 +4,16 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
public class TitleTest { public class TitleTest {
@Test /* @Test
public void TestTitle() throws InterruptedException { public void TestTitle() throws InterruptedException {
GuestBookWebPage.getTitle(); GuestBookWebPage.getTitle();
Assert.assertEquals("Guest Book", GuestBookWebPage.title); Assert.assertEquals("Guest Book", GuestBookWebPage.title);
System.out.println("The expected is: Guest Book and the actual is: " + 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!");
} }
} }