Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Hotels.com FirstSprint #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file modified drivers/chromedriver
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/test/.DS_Store
Binary file not shown.
Binary file added src/test/java/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package Class1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/Class1/Homework1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Class1;

public class Homework1 {

/**
*
* Due Date: Tue (Apr 19)
*
*
* Create new repository in Github
* Invite Ahsan or Fara as Collaborator in the repository
* Clone repository in local
* Create a branch
* Checkout to the branch
* Create a Maven Project in the above cloned repository
* Add TestNG and Selenium dependencies in the pom.xml-file
* Check the version of Chrome installed in your machine
* Download and save the compatible ChromeDriver
* Create a new package in src/test/java
* Create a new class in above create package
* Create a Test-method in above created class using @Test annotation
* Write code to Launch amazon.com (https://www.amazon.com/)
*
* Push all code in the github
* Create a new Pull request and assign it to the Collaborator (Lab Instructor)
*
*/
}
21 changes: 21 additions & 0 deletions src/test/java/Class1/UseSelenium.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Class1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class UseSelenium {

@Test
public void useSeleniumLib() {

// path of chromedriver
System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver"); // Mac
// System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver.exe"); // Windows

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

}
}
49 changes: 49 additions & 0 deletions src/test/java/Class1/UseTestNG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package Class1;

import org.testng.Assert;
import org.testng.annotations.Test;

public class UseTestNG {

/**
* Use of TestNG:
* 1. to create Test Method
* 2. to assert a test step
* assertEquals -> use when what to compare two values to be equal/identical
* eg: Assert.assertEquals(val1, val2, msg)
* Here, we are verifying if val1 is equals to val2
* if equals, the test-Step will pass
* else the testcase will fail, and msg will be printed out
*
* assertTrue -> use when what to check if a boolean is true
* eg: Assert.assertTrue(val, msg)
* Here, we are verifying if val is true
* if val is true, the test-Step will pass
* else the testcase will fail, and msg will be printed out
*
* assertFalse -> use when what to check if a boolean is false
* eg: Assert.assertFalse(val, msg)
* Here, we are verifying if val is false
* if val is false, the test-Step will pass
* else the testcase will fail, and msg will be printed out
*
*
* Use of Selenium:
* to automate the web-testcases
*
*/

@Test // Test - Annotation from testNG Library
public void verify2Plus2Is4() {
// Assert Library is part of TestNG Library
Assert.assertEquals(2+2 , 14, "2+2 is not coming as expected");

}


@Test
public void verify3Plus3Is6() {
// Assert
Assert.assertEquals(3+3 , 6, "3+3 is not coming as expected");
}
}
171 changes: 171 additions & 0 deletions src/test/java/Class2/BasicMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package Class2;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class BasicMethods {

@Test
public void basicMethods() {

// path of chromedriver
System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver");

WebDriver driver = new ChromeDriver();
/**
* WebDriver is an Interface
* ChromeDriver/FirefoxDriver is a Class (which is related to WebDriver Interface)
*
* WebDriver driver -> driver is a variable of WebDriver Interface
* new ChromeDriver() -> object of ChromeDriver class
*
* WebDriver driver = new ChromeDriver();
* Storing ChromeDriver-object into WebDriver-variable.
*
* ChromeDriver(C) extends RemoteWebDriver(C) ; RemoteWebDriver(C) implements WebDriver(I)
*
*/

/**
* To launch a webpage
*
* Method-1 : get()
*
* Method-2 : navigate().to()
*/
String url = "https://www.facebook.com/";
driver.get(url);
// OR
// driver.navigate().to(url);
/**
* get() vs navigate().to()
*
* get() -> launches the webpage and wait for few seconds (for webpage to load)
* before executing the next line in the code
*
* navigate().to() -> launches the webpage
* and goes to execute the next line in the code
*/

// Sleep so that webpage loads completely (temporary solution)
try {
Thread.sleep(5000); // sleep for 5-seconds
} catch (InterruptedException e) {
e.printStackTrace();
}

/**
* Method to maximize the webpage
*
* method: maximize()
*/
// driver.manage().window().maximize();

/**
* To get the url from browser-window
*
* method: getCurrentUrl()
* Return type: String
*/
String currentUrl = driver.getCurrentUrl();
System.out.println("Current url -> " + currentUrl);

/**
* To get page title of the webpage
*
* method: getTitle()
*/
String pageTitle = driver.getTitle();
System.out.println("Page title -> " + pageTitle);

/**
* To back/forward in a web-browser
*
* method : back()
* method : forward()
*/
driver.navigate().back();

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Page title -> " + driver.getTitle());

driver.navigate().forward();

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Page title -> " + driver.getTitle());


/**
* To refresh a webpage
*
* Method-1: click refresh-icon (method: refresh())
*
* Method-2: go back then forward
*
* Method-3: Launch the current url
*
*/
// 1
driver.navigate().refresh();

// 2
driver.navigate().back();
driver.navigate().forward();

// 3
/*
1. get the current url (getCurrentUrl)
2. launch the url got from step-1 (get)
*/
String myUrl = driver.getCurrentUrl();
driver.get(myUrl);

/**
* To close a webpage
*
* Method-1 : close()
* will close ONLY web-window associated/connected with driver
*
*
* Method-2 : quit()
* will close ALL web-windows opened due to automation code/script
*/
// driver.close();
}

// Verify correct url is launch
/*
Open a browser window
Launch facebook.com
verify currentUrl is facebook.com

*/
@Test
public void verifyCorrectUrl() {
System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver");
WebDriver driver = new ChromeDriver();
String url = "https://www.facebook.com/";
driver.get(url);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}

String currentUrl = driver.getCurrentUrl();

Assert.assertEquals(url, currentUrl, "Current url is NOT same as launched url");


}
}
65 changes: 65 additions & 0 deletions src/test/java/Class2/BasicMethods_Practice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package Class2;

import Helper.Misc;
import Web.MyDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class BasicMethods_Practice {

// TC-1: Verify the facebook page title starts with "facebook" on facebook home page
/*
Steps:
1. Launch a new browser window
2. Open facebook.com
3. Verify page title starts with "facebook"
*/
@Test
public void verifyTitle() {
MyDriver.launchUrlOnNewWindow("https://www.facebook.com/");

String pageTitle = MyDriver.getDriver().getTitle();
boolean isStartsWith_facebook = pageTitle.startsWith("facebook");
Assert.assertTrue(isStartsWith_facebook , "Facebook title does NOT start with 'facebook'");

MyDriver.quitWindows();

}

// TC-2: Verify the url stays same after refreshing the facebook home page
/*
1. Launch a new browser window
2. Open facebook.com
3. Observe the url-value
4. Refresh the webpage
5. Verify url value is same as of Step-3

*/
@Test
public void verifyUrlAfterRefresh() {
MyDriver.launchUrlOnNewWindow("https://www.facebook.com/");

String urlAfterLaunch = MyDriver.getDriver().getCurrentUrl();

MyDriver.getDriver().navigate().refresh();
Misc.pause(5);

String urlAfterRefresh = MyDriver.getDriver().getCurrentUrl();
Assert.assertEquals(urlAfterLaunch, urlAfterRefresh, "Facebook url is NOT same after refresh");

MyDriver.quitWindows();
}

// TC-3: Verify current url is ending with "/" on facebook home page
@Test
public void verifyUrlEnding() {
MyDriver.launchUrlOnNewWindow("https://www.facebook.com/");

String urlAfterLaunch = MyDriver.getDriver().getCurrentUrl();

boolean urlEndsWith_Slash = urlAfterLaunch.endsWith("/");
Assert.assertTrue(urlEndsWith_Slash, "Facebook url does NOT end with '/'");

MyDriver.quitWindows();
}
}
9 changes: 9 additions & 0 deletions src/test/java/Class3/Class3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Class3;

public class Class3 {





}
Loading