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

Use sauce demo #18

Open
wants to merge 8 commits into
base: master
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
jdk:
- oraclejdk8
- oraclejdk9
before_install:
- export | grep SAUCE_
script: mvn clean test
Expand Down
64 changes: 0 additions & 64 deletions src/test/java/com/yourcompany/Pages/GuineaPigPage.java

This file was deleted.

41 changes: 41 additions & 0 deletions src/test/java/com/yourcompany/Tests/AddItemsToCartTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.yourcompany.Tests;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

public class AddItemsToCartTest extends TestBase {

public AddItemsToCartTest(String os,
String version, String browser, String deviceName, String deviceOrientation) {
super(os, version, browser, deviceName, deviceOrientation);
}

@Test
public void addOneItem(){
driver.get("http://www.saucedemo.com/inventory.html");
driver.findElement(By.className("btn_primary")).click();

Assert.assertEquals(driver.findElement(By.className("shopping_cart_badge")).getText(), "1");

driver.get("http://www.saucedemo.com/cart.html");
long expected = driver.findElements(By.className("inventory_item_name")).size();

Assert.assertEquals(expected, 1);

}

@Test
public void addTwoItems(){
driver.get("http://www.saucedemo.com/inventory.html");
driver.findElement(By.className("btn_primary")).click();
driver.findElement(By.className("btn_primary")).click();

Assert.assertEquals(driver.findElement(By.className("shopping_cart_badge")).getText(), "2");

driver.get("http://www.saucedemo.com/cart.html");
long expected = driver.findElements(By.className("inventory_item_name")).size();

Assert.assertEquals(expected, 2);
}
}
28 changes: 0 additions & 28 deletions src/test/java/com/yourcompany/Tests/FollowLinkTest.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/test/java/com/yourcompany/Tests/InvalidLoginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.yourcompany.Tests;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

public class InvalidLoginTest extends TestBase {

public InvalidLoginTest(String os,
String version, String browser, String deviceName, String deviceOrientation) {
super(os, version, browser, deviceName, deviceOrientation);
}

@Test
public void blankCredentials(){
driver.get("http://www.saucedemo.com");

driver.findElement(By.id("user-name")).sendKeys("");
driver.findElement(By.id("password")).sendKeys("");
driver.findElement(By.cssSelector(".btn_action")).click();

Assert.assertTrue(driver.findElement(By.cssSelector(".error-button")).isDisplayed());
}
}
28 changes: 28 additions & 0 deletions src/test/java/com/yourcompany/Tests/RemoveItemFromCartTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yourcompany.Tests;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

public class RemoveItemFromCartTest extends TestBase {

public RemoveItemFromCartTest(String os,
String version, String browser, String deviceName, String deviceOrientation) {
super(os, version, browser, deviceName, deviceOrientation);
}

@Test
public void removeOne() {

driver.get("http://www.saucedemo.com/inventory.html");
driver.findElement(By.className("btn_primary")).click();
driver.findElement(By.className("btn_primary")).click();
driver.findElement(By.className("btn_secondary")).click();

Assert.assertEquals(driver.findElement(By.className("shopping_cart_badge")).getText(), "1");

driver.get("http://www.saucedemo.com/cart.html");
long expected = driver.findElements(By.className("inventory_item_name")).size();
Assert.assertEquals(expected, 1);
}
}
19 changes: 10 additions & 9 deletions src/test/java/com/yourcompany/Tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.saucelabs.junit.ConcurrentParameterized;
import com.saucelabs.junit.SauceOnDemandTestWatcher;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;

Expand Down Expand Up @@ -91,11 +92,11 @@ public TestBase(String os, String version, String browser, String deviceName, St
public static LinkedList browsersStrings() {
LinkedList browsers = new LinkedList();

browsers.add(new String[]{"Windows 10", "14.14393", "MicrosoftEdge", null, null});
browsers.add(new String[]{"Windows 10", "49.0", "firefox", null, null});
browsers.add(new String[]{"Windows 7", "11.0", "internet explorer", null, null});
browsers.add(new String[]{"OS X 10.11", "10.0", "safari", null, null});
browsers.add(new String[]{"OS X 10.10", "54.0", "chrome", null, null});
browsers.add(new String[]{"Windows 10", "latest", "firefox", null, null});
browsers.add(new String[]{"MacOS 10.14", "12", "safari", null, null});
browsers.add(new String[]{"MacOS 10.13", "latest", "chrome", null, null});
browsers.add(new String[]{"Windows 10", "latest-1", "firefox", null, null});
browsers.add(new String[]{"Windows 10", "11.0", "internet explorer", null, null});
return browsers;
}

Expand All @@ -104,10 +105,10 @@ public static LinkedList browsersStrings() {
* {@link #version} and {@link #os} instance variables, and which is configured to run against ondemand.saucelabs.com, using
* the username and access key populated by the {@link #authentication} instance.
*
* @throws Exception if an error occurs during the creation of the {@link RemoteWebDriver} instance.
* @throws MalformedURLException if an error occurs during the creation of the {@link RemoteWebDriver} instance.
*/
@Before
public void setUp() throws Exception {
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
Expand All @@ -121,8 +122,8 @@ public void setUp() throws Exception {

//Getting the build name.
//Using the Jenkins ENV var. You can use your own. If it is not set test will run without a build id.
if (buildTag != null) {
capabilities.setCapability("build", buildTag);
if (buildTag == null) {
capabilities.setCapability("build", "joshs-build");
}
this.driver = new RemoteWebDriver(
new URL("https://" + username+ ":" + accesskey + seleniumURI +"/wd/hub"),
Expand Down
33 changes: 0 additions & 33 deletions src/test/java/com/yourcompany/Tests/TextInputTest.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/test/java/com/yourcompany/Tests/ValidLoginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.yourcompany.Tests;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

public class ValidLoginTest extends TestBase {

public ValidLoginTest(String os,
String version, String browser, String deviceName, String deviceOrientation) {
super(os, version, browser, deviceName, deviceOrientation);
}

@Test
public void standardUser(){
driver.get("http://www.saucedemo.com");

driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.id("password")).sendKeys("secret_sauce");
driver.findElement(By.cssSelector(".btn_action")).click();

Assert.assertTrue(driver.getCurrentUrl().contains("inventory.html"));
}
}