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

Verify user can add an item successfully #8

Open
wants to merge 8 commits into
base: mounika
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>

</dependencies>
</project>
17 changes: 17 additions & 0 deletions src/main/java/automation/pages/AddressPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class AddressPage extends BasePage {
public AddressPage(){
PageFactory.initElements(driver,this);
}
@FindBy(xpath = "//*[@id='center_column']/form/p/button")
WebElement proceedToCheckout;
public void setProceedToCheckout(){
proceedToCheckout.click();
}

}
33 changes: 33 additions & 0 deletions src/main/java/automation/pages/AuthenticationPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class AuthenticationPage extends BasePage {
public AuthenticationPage(){
PageFactory.initElements(driver,this);
}
@FindBy(xpath = "//*[@id='center_column']/h1")
WebElement authenticationPageHeader;
@FindBy(id="email")
WebElement email_AlreadyRegistered;
@FindBy(id = "passwd")
WebElement password_AlreadyRegistered;
@FindBy(id="SubmitLogin")
WebElement submitLogin;
public boolean isUserOnAuthenticationPage(){
return Utils.isElementPresent(authenticationPageHeader);
}
public void setEmail_AlreadyRegistered(String emailAlreadyExisting){
email_AlreadyRegistered.sendKeys(emailAlreadyExisting);

}
public void setPassword_AlreadyRegistered(String passwordAlreadyExisting){
password_AlreadyRegistered.sendKeys(passwordAlreadyExisting);
}
public void setSubmitLogin(){
submitLogin.click();
}

}
8 changes: 5 additions & 3 deletions src/main/java/automation/pages/BasePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ public class BasePage {
public static String url="http://automationpractice.com/index.php";

public static void startBrowser() {
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Neerav\\Downloads/chromedriver.exe");
driver = new ChromeDriver();
driver.get(url);
driver.manage().timeouts().implicitlyWait(10000,TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(url);
// driver.manage().timeouts().implicitlyWait(10000,TimeUnit.SECONDS);


}
public static void closebrowser() {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/automation/pages/BasketPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package automation.pages;

/**
* Created by User on 22/10/2017.
*/
public class BasketPage extends BasePage{

}
31 changes: 27 additions & 4 deletions src/main/java/automation/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class HomePage extends BasePage {
public HomePage(){PageFactory.initElements(driver,this);}

@FindBy(xpath="//*[@class='login']")
WebElement signinbtn;
Expand All @@ -27,6 +29,17 @@ public class HomePage extends BasePage {
WebElement addTocomparebtnForitem4;
@FindBy(xpath="html/body/div[1]/div[2]/div/div[3]/div[2]/div[1]/div[2]/form/button")
WebElement compareBtn;
@FindBy(xpath = "//*[@id='block_top_menu']/ul/li[1]/a")
WebElement women_Link;
@FindBy(id = "search_query_top")
WebElement search;
@FindBy(xpath = "//*[@id='searchbox']/button")
WebElement searchButton;
@FindBy(xpath = "//*[@id='homefeatured']/li[1]/div/div[1]/div/a[1]/img")
WebElement product1;
@FindBy(xpath = "//*[@id='homefeatured']/li[1]/div/div[2]/div[2]/a[1]/span")
WebElement addToCartProduct1;


//for a valid user name and password who already registered
public void signin() {
Expand All @@ -42,8 +55,8 @@ public void contactUsLinkPresence() {
public void search(String itemname) {
searchBox.sendKeys(itemname);
searchclickbtn.click();
boolean res1=Utils.isElementPresent(By.xpath("//*[@class='heading-counter']"));
Assert.assertTrue(res1);
//boolean res1=Utils.isElementPresent(By.xpath("//*[@class='heading-counter']"));
//Assert.assertTrue(res1);

}

Expand All @@ -65,10 +78,20 @@ public void addToCompare() throws Exception {
addTocomparebtnForitem5.click();
Thread.sleep(1000);
compareBtn.click();
boolean res=Utils.isElementPresent(By.xpath("//*[@class='page-heading']"));
Assert.assertTrue(res);
// boolean res=Utils.isElementPresent(By.xpath("//*[@class='page-heading']"));
// Assert.assertTrue(res);

}
public void waitForItem(){
Utils.waitForElementVisible(product1,3000);
}
public void setProduct1(){
Utils.mouseHover(product1);
}
public void setAddToCartProduct1(){
addToCartProduct1.click();

}



Expand Down
14 changes: 14 additions & 0 deletions src/main/java/automation/pages/PaymentMethodPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class PaymentMethodPage extends BasePage {
public PaymentMethodPage(){PageFactory.initElements(driver,this);}
@FindBy(xpath = "//*[@id='center_column']/h1")
WebElement paymentMethodHeader;
public boolean isUserOnPaymentMethodPage(){
return Utils.isElementPresent(paymentMethodHeader);
}
}
20 changes: 20 additions & 0 deletions src/main/java/automation/pages/ProceedToCheckOutPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class ProceedToCheckOutPage extends BasePage {
public ProceedToCheckOutPage(){
PageFactory.initElements(driver,this);
}
@FindBy(linkText = "Proceed to checkout")
WebElement proceedToCheckout;
public void setProceedToCheckout(){
proceedToCheckout.click();
}
public void waitForProceedToCheckoutElement(){
Utils.waitForElementVisible(proceedToCheckout,3000);
}

}
16 changes: 16 additions & 0 deletions src/main/java/automation/pages/ReusableFunctions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class ReusableFunctions extends BasePage {
public ReusableFunctions(){
PageFactory.initElements(driver,this);}
@FindBy(id = "selectProductSort")
WebElement selectProductSort;
public void setSelectProductSort(String text){
Utils.selectFromList(selectProductSort,text);
}

}
20 changes: 20 additions & 0 deletions src/main/java/automation/pages/ShippingPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class ShippingPage extends BasePage {
public ShippingPage(){
PageFactory.initElements(driver,this);
}
@FindBy(id="cgv")
WebElement shippingPageCheckbox;
@FindBy(xpath = "//*[@id='form']/p/button")
WebElement proceedToCheckout;
public void setShippingPageCheckbox(){ shippingPageCheckbox.click();}
public void setProceedToCheckout(){
proceedToCheckout.click();
}

}
24 changes: 24 additions & 0 deletions src/main/java/automation/pages/SummaryPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package automation.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class SummaryPage extends BasePage {
public SummaryPage(){
PageFactory.initElements(driver,this);
}
@FindBy(xpath = "//*[@id='cart_title']")
WebElement summaryPageHeader;
@FindBy(linkText = "Proceed to checkout")
WebElement proceedToCheckout;
public void setProceedToCheckout(){
proceedToCheckout.click();
}
public boolean isUserOnSummaryPage(){
return Utils.isElementPresent(summaryPageHeader);
}
public void waitForProceedToCheckOutInSummaryPage(){
Utils.waitForElementVisible(proceedToCheckout,3000);
}
}
28 changes: 25 additions & 3 deletions src/main/java/automation/pages/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

public class Utils extends BasePage {
public static boolean isElementPresent(By element) {
return driver.findElement(element).isDisplayed();
static WebDriverWait wait;

public static boolean isElementPresent(WebElement element) {
return element.isDisplayed();

}
public static void selectFromList(WebElement element,String text) {
Expand All @@ -17,8 +24,23 @@ public static void selectFromList(WebElement element,String text) {

public static void scrollbyY(WebElement elementlocator) {
WebElement ele=driver.findElement((By) elementlocator);
((JavascriptExecutor)driver).executeScript("window.scrollTo(0,"+ele.getLocation().y+")");
((JavascriptExecutor)driver).executeScript("window.scrollTo(0," + ele.getLocation().y + ")");

}
public static void waitForElementVisible(WebElement element, int time) {
wait = new WebDriverWait(driver,time);
wait.until(ExpectedConditions.visibilityOf(element));
}
//Method for Single element Mouse Hover
public static void mouseHover(WebElement element){
Actions action=new Actions(driver);
action.moveToElement(element).perform();

}
//Method for implicit wait
public static void implicitlyWait(int time){
driver.manage().timeouts().implicitlyWait(time, TimeUnit.MILLISECONDS);
}


}
4 changes: 2 additions & 2 deletions src/test/java/automation/BaseTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public static void openbrowser() {
BasePage.startBrowser();

}
@AfterClass
/*@AfterClass
public static void closedown() {
BasePage.closebrowser();
}
}*/


}
49 changes: 42 additions & 7 deletions src/test/java/automation/HomePageTests.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
package automation;

import automation.pages.ContactUsPage;
import automation.pages.HomePage;
import automation.pages.SigninPage;
import automation.pages.*;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.support.PageFactory;



public class HomePageTests extends BaseTests {

//Test Data
String sortByData="Price: Lowest first";
int timetowait=3000;
String emailExisting="[email protected]";
String passwordExisting="secret123";
//Creating objects
HomePage homePage=new HomePage();
ProceedToCheckOutPage proceedToCheckOutPage=new ProceedToCheckOutPage();
SummaryPage summaryPage=new SummaryPage();
AuthenticationPage authenticationPage=new AuthenticationPage();
AddressPage addressPage=new AddressPage();
ShippingPage shippingPage=new ShippingPage();
PaymentMethodPage paymentMethodPage=new PaymentMethodPage();
@Test
public void verifyContactUs() {
ContactUsPage contactus=PageFactory.initElements(driver,ContactUsPage.class);
HomePage homepage=PageFactory.initElements(driver,HomePage.class);
homepage.contactUsLinkPresence();

}

@Test
Expand All @@ -28,9 +40,32 @@ public void verifySignIn() throws Exception {
homepage.listveiw();
homepage.sortby("Price: Lowest first");
homepage.addToCompare();
}


}

@Test
public void verifyUserCanAddAnItemSuccessfully(){
homePage.waitForItem();
homePage.setProduct1();
homePage.setAddToCartProduct1();
proceedToCheckOutPage.waitForProceedToCheckoutElement();
proceedToCheckOutPage.setProceedToCheckout();
System.out.println(summaryPage.isUserOnSummaryPage());
Assert.assertTrue(summaryPage.isUserOnSummaryPage());
summaryPage.waitForProceedToCheckOutInSummaryPage();
summaryPage.setProceedToCheckout();
Assert.assertTrue(authenticationPage.isUserOnAuthenticationPage());
authenticationPage.setEmail_AlreadyRegistered(emailExisting);
authenticationPage.setPassword_AlreadyRegistered(passwordExisting);
authenticationPage.setSubmitLogin();
Utils.implicitlyWait(timetowait);
addressPage.setProceedToCheckout();
Utils.implicitlyWait(timetowait);
shippingPage.setShippingPageCheckbox();
shippingPage.setProceedToCheckout();
Assert.assertTrue(paymentMethodPage.isUserOnPaymentMethodPage());

}

}