Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ repositories {
dependencies {

compile group: 'junit', name: 'junit', version: '4.12'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to add this dependency in the project



}

Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/SeleniumExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.jalasoft.selenium.leonardo;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.support.ui.Select;

/**
* Created by Automation on 3/10/2017.
*/
public class SeleniumExample {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this unnecessary class


@Test
public void testSelenium(){

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("http://only-testing-blog.blogspot.in/2013/09/test.html");

WebElement firstNameTextField = driver.findElement(By.id("fname"));
firstNameTextField.sendKeys("Carlos");

WebElement lastNameTextField = driver.findElement(By.name("lname"));
System.out.println(firstNameTextField.isEnabled());
System.out.println(lastNameTextField.isEnabled());

WebElement bikeCheckBox = driver.findElement(By.cssSelector("input[value='Bike'"));

//select checkbox
if(!bikeCheckBox.isSelected()) {
bikeCheckBox.click();
System.out.println("was not selected");
}

//clear checkbox
if(bikeCheckBox.isSelected()) {
bikeCheckBox.click();
System.out.println("was selected");
}


WebElement maleRadioButton = driver.findElement(By.cssSelector("input[value='male']"));
maleRadioButton.click();

//aplica a select normales <select>
Select selectBox = new Select(driver.findElement(By.xpath("//select")));

selectBox.selectByValue("UK");

selectBox.selectByVisibleText("Opel");

selectBox.selectByIndex(3);

Select selectBoxMultipleL = new Select(driver.findElement(By.name("FromLB")));

//single select in multiple
selectBoxMultipleL.selectByValue("JPN");
WebElement buttonToRight = driver.findElement(By.cssSelector("input[value='->']"));
buttonToRight.click();

//multiple select in multiple
selectBoxMultipleL.selectByValue("ESP");
selectBoxMultipleL.selectByValue("RUS");
selectBoxMultipleL.selectByValue("IND");
buttonToRight.click();

Select selectBoxMultipleR = new Select(driver.findElement(By.name("ToLB")));
selectBoxMultipleR.selectByValue("IND");

WebElement buttonToLeft = driver.findElement(By.cssSelector("input[value='<-']"));
buttonToLeft.click();


System.out.println();



}
}
124 changes: 124 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.jalasoft.selenium.leonardo.movies;

import java.util.Enumeration;
import java.util.Vector;

/**
*
*/
public class Customer {
private String name;
private Vector rentalsV = new Vector();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a List instead of a Vector.


/**
*
* @param nameM name of the customer
*/
public Customer(String nameM) {
name = nameM;
}

/**
*
* @param arg add rental data to the vector
*/
public void addRental(Rental arg) {
rentalsV.addElement(arg);
}

/**
*
* @return name of the customer
*/
public String getName() {
return name;
}

/**
*
* @return the statement format of what the customer owes from rentals
*/
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = rentalsV.elements();
String result = "Rental Record for " + getName() + "\n";
while (rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental) rentals.nextElement();
//determine amounts for each line
switch (each.getMovie().getPriceCode()) {
case Movie.REGULAR: /**0*/
thisAmount += 2;
if (each.getDaysRented() > 2) {
thisAmount += (each.getDaysRented() - 2) * 1.5;
}
break;
case Movie.NEW_RELEASE: /**1*/
thisAmount += each.getDaysRented() * 3;
break;
case Movie.CHILDRENS: /**2*/
thisAmount += 1.5;
if (each.getDaysRented() > 3) {
thisAmount += (each.getDaysRented() - 3) * 1.5;
}
break;
default: break;
}
// add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE)
&&
each.getDaysRented() > 1) { frequentRenterPoints++; }
//show figures for this rental
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
//add footer lines
result += "Amount owed is " + String.valueOf(totalAmount) +
"\n";
result += "You earned " + String.valueOf(frequentRenterPoints)
+
" frequent renter points";
return result;
}

/**
* this method is the initial refactor
* @return the statement format of what the customer owes from rentals
*/

public String statement2() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = rentalsV.elements();
String result = "Rental Record for " + getName() + "\n";
while (rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental) rentals.nextElement();
//determine amounts for each line

thisAmount = each.getMovie().getAmount(each.getMovie().getPriceCode(),each.getDaysRented());

// add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE)
&&
each.getDaysRented() > 1) { frequentRenterPoints++; }
//show figures for this rental
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
//add footer lines
result += "Amount owed is " + String.valueOf(totalAmount) +
"\n";
result += "You earned " + String.valueOf(frequentRenterPoints)
+
" frequent renter points";
return result;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jalasoft.selenium.leonardo.movies;

/**
*
*/
public class Main {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this unnecessary class
because it will replaced by unit tests

/**
*
* @param args program execution options from command line
*/
public static void main(String[] args) {
Customer customer = new Customer("Test");
customer.addRental(new Rental(new Movie("The Revenant", 1), 2));
customer.addRental(new Rental(new Movie("Terminator", 0), 2));
System.out.println(customer.statement2());
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.jalasoft.selenium.leonardo.movies;

/**
*
*/
public class Movie extends movieType {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should have a parent Movie class
and child classes for NewRelease, Children, and Regular that extends from Movie class

public static final int CHILDRENS = 2;
public static final int REGULAR = 0;
public static final int NEW_RELEASE = 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need to keep those constants ?
you need to take advantage of inheritance here.

private String title;
private int priceCode;

/**
*
* @param titleM title of the movie
* @param priceCodeM price code of the movie
*/
public Movie(String titleM, int priceCodeM) {
title = titleM;
priceCode = priceCodeM;
}

/**
*
* @return price cod eof the movie
*/

public int getPriceCode() {
return priceCode;
}

/**
*
* @param arg price code
*/
public void setPriceCode(int arg) {
priceCode = arg;
}

/**
*
* @return title of the movie
*/
public String getTitle() {
return title;
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Rental.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.jalasoft.selenium.leonardo.movies;

/**
*
*/
public class Rental {
private Movie movie;
private int daysRented;

/**
*
* @param movieM movie name
* @param daysRentedM number of days rented
*/
public Rental(Movie movieM, int daysRentedM) {
movie = movieM;
daysRented = daysRentedM;
}

/**
*
* @return number of days rented
*/

public int getDaysRented() {
return daysRented;
}

/**
*
* @return movie
*/
public Movie getMovie() {
return movie;
}
}
Loading