Repository navigation
Adding Shape and Movies projects. #11
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
base: develop
Are you sure you want to change the base?
Changes from 4 commits
5377c07
4cd4464
4bdf7a4
2606480
510ad3f
c93583a
90dc6f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| 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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.jalasoft.selenium.leonardo.movies; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class Main { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this unnecessary class |
||
| /** | ||
| * | ||
| * @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()); | ||
| } | ||
| } | ||
| 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should have a parent Movie class |
||
| public static final int CHILDRENS = 2; | ||
| public static final int REGULAR = 0; | ||
| public static final int NEW_RELEASE = 1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you still need to keep those constants ? |
||
| 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; | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
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