Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a automation End-to-End integration test case using Selenium Web Driver J

ID: 649440 • Letter: C

Question

Create a automation End-to-End integration test case using Selenium Web Driver Junit 4.
choosing from following domains

(1) E-Commerce - Amazon, eBay, TOYOTA
(2) Financials - Bank of America
(3) Internet Service Provider - Yahoo, Google
(4) Social Media - Facebook, LinkedIn, Twitter
(5) Cloud Computing - Salesforce
(6) Health Care - Covered California

End to End use case example:
Rajesh opens NPU web page, goes through the main home page
Open Admissions to check some quick links
Open Academics to learn more details
Open Campus and go through NPU Campus tour
Check more information (e.g. News and Blogs)
Go to Online Application to register

TestGoogleMapByKeys.txt :

package JavaSeleniumTests;

import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;


public class testGoogleMapByKeys {

   public WebDriver driver;
   public String baseUrl = "http://www.google.com";
   public String searchText = "Northwestern Polytechnic University";
   Actions action;
  
   //@Ignore
   @Test
   public void testGoogleMapNPU() throws Exception{
      
       // open Google home page, see @Before

       // click Google Options
       driver.findElement(By.cssSelector(".gb_K")).click();
       sleep(2);
       moveTabKey(4); // Google Map
       hitEnterKey();
       sleep(2);      

       // Google Map search text input and hit enter key
       driver.findElement(By.id("searchboxinput")).sendKeys(searchText);
       hitReturnKey();
       sleep(2);
      
       // move key down and up in google map
       moveDownKey(3);
       moveUpKey(3);
      
       // move mouse back to google map search text to enable NPU Street View picture
       driver.findElement(By.id("searchboxinput")).click();
       sleep(1);
      
       // click and open Street View
       driver.findElement(By.xpath("/html/body/jsl/div/div[7]/div[4]/div[1]/div[2]/div[4]/div/div/div[1]/button[1]")).click();
       sleep(2);
      
       //hitEnterKey();
       //hitReturnKey();
       //action.doubleClick();
       //moveLeftKey(10);
       //moveRightKey(10);
      
       moveDownKey(10);
       moveUpKey(10);

       this.sleep(3);
   }

   @Before
   public void setUp() throws Exception {
      driver = new FirefoxDriver();
      driver.navigate().to(baseUrl);
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      this.sleep(1);
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      this.sleep(1);
   }
     
   @After
   public void tearDown() throws Exception {
      driver.quit(); // close all
   }
  
   public void moveTabKey(int times){
       for (int i=1; i<=times; i++){
           action = new Actions(driver);
           action.sendKeys(Keys.TAB).build().perform();
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
           this.sleep(1);
       }
   }
  
   public void moveDownKey(int times){
       for (int i=1; i<=times; i++){
           action = new Actions(driver);
           action.sendKeys(Keys.DOWN).build().perform();
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
           this.sleep(1);
       }
   }
  
   public void moveUpKey(int times){
       for (int i=1; i<=times; i++){
           action = new Actions(driver);
           action.sendKeys(Keys.UP).build().perform();
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
           this.sleep(1);
       }
   }
  
   public void moveRightKey(int times){
       for (int i=1; i<=times; i++){
           action = new Actions(driver);
           action.sendKeys(Keys.RIGHT).build().perform();
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
           this.sleep(1);
       }
   }
  
   public void moveLeftKey(int times){
       for (int i=1; i<=times; i++){
           action = new Actions(driver);
           action.sendKeys(Keys.LEFT).build().perform();
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
           this.sleep(1);
       }
   }
  
   public void hitEnterKey(){
       action = new Actions(driver);
       action.sendKeys(Keys.ENTER).build().perform();
       driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
       this.sleep(1);
   }
  
   public void hitReturnKey(){
       action = new Actions(driver);
       action.sendKeys(Keys.RETURN).build().perform();
       driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
       this.sleep(1);
   }
  
   public void sleep(int seconds)
   {
       try {
           Thread.sleep(seconds * 1000);
       } catch (InterruptedException e) {

       }
   }
}

TestOpenNewWindow.txt :

package JavaSeleniumTests;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class testOpenNewWindow {
  
   public WebDriver driver;
   WebElement scroll;
   public String baseUrl = "http://www.npu.edu";
   public String newUrl = "https://www.facebook.com/NPUadmissions";
   public String searchText = "Northwestern Polytechnic University";
  
   //@Ignore
   @Test
   public void testOpenFacebookFromNPU() throws Exception{
      
       // open Google home page, see @Before
      
       // remember current window (NPU home page)
       String parentHandle = driver.getWindowHandle();
      
       // click icon of Link Us on Facebook!
       driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/ul/li[1]/a")).click(); // Link Us on Facebook!
       this.sleep(1);
       driver.navigate().to(newUrl);
       this.sleep(3);
      
       // scroll down page by finding a web element
       driver.findElement(By.linkText(searchText));
      
       // scroll down page by Keys.PAGE_DOWN
       scroll = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div[5]/div/div[1]/div/div/div[5]/div/div[4]/div/div/div/a"));
       scroll.sendKeys(Keys.PAGE_DOWN);
       this.sleep(2);

       // scroll down page by Keys.PAGE_DOWN
       scroll = driver.findElement(By.xpath("/html/body/div/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div[5]/div/div[1]/div/div/div[2]/div/div[2]/a"));
       scroll.sendKeys(Keys.PAGE_DOWN);
       this.sleep(2);
      
       // select and open a event, then close it
       driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div[5]/div/div[1]/div/div/div[5]/div/div[4]/div/div/div/a")).click();
       this.sleep(2);
       driver.navigate().back();
      
       // scroll up page by Keys.PAGE_UP
       scroll = driver.findElement(By.xpath("/html/body/div/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div/div[1]/div[2]/div/div[1]/div/div/a[1]/span"));
       scroll.sendKeys(Keys.PAGE_UP);
       this.sleep(2);
      
       // scroll up page to top by Keys.PAGE_UP
       scroll = driver.findElement(By.id("email"));
       scroll.sendKeys(Keys.PAGE_UP);
       this.sleep(2);

       // open Facebook Sign Up
       driver.findElement(By.xpath("/html/body/div/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div/div[1]/div[2]/div/div[1]/div/div/a[1]/span")).click();
       this.sleep(2);
      
       // go back to Facebook NPU
       driver.navigate().back();
       this.sleep(2);

       // go back to NPU home page
       driver.navigate().back();
       this.sleep(2);

       driver.switchTo().window(parentHandle); // switch back
       this.sleep(1);
      
       // click a image and close it
       driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div[1]/div[1]/div[2]/p[1]/a/img")).click();
       this.sleep(3);
       driver.findElement(By.xpath("/html/body/div[4]/div[3]/div/div/div/div[2]/div[3]/a")).click();
       this.sleep(2);
      
       // close all see @After
   }

  
   @Before
   public void setUp() throws Exception {
      driver = new FirefoxDriver();
      driver.navigate().to(baseUrl);
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      this.sleep(1);
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      this.sleep(1);
   }
     
   @After
   public void tearDown() throws Exception {
      driver.quit(); // close all
   }
  
   public void sleep(int seconds)
   {
       try {
           Thread.sleep(seconds * 1000);
       } catch (InterruptedException e) {

       }
   }
}

Explanation / Answer

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.Assert;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

import org.testng.annotations.AfterClass;

public class TestClass1

{

protected static WebDriver wd;

            protected static String result;

            @BeforeClass

public static void setup()

{

            wd = new FirefoxDriver();

            wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

}

            @Test

void Testcase1()

{

            wd.findElement(By.id("kwsch")).sendKeys("Red");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

Assert.assertEquals(result, "115");

}

            @Test

void Testcase2() {

            wd.findElement(By.id("kwsch")).sendKeys("Blue");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

            Assert.assertEquals(result, "13");

}

            @Test

void Testcase3() {

            wd.findElement(By.id("kwsch")).sendKeys("Yellow");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

            Assert.assertEquals(result, "27");

}

            @Test

void Testcase4() {

            wd.findElement(By.id("kwsch")).sendKeys("Purple");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

            Assert.assertEquals(result, "10");

}

@AfterClass

public static void teardown() {

            wd.close();

            wd.quit();

}

}

for testing in browser

for testing in browser

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.Assert;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

import org.testng.annotations.AfterClass;

public class TestClass1

{

protected static WebDriver wd;

            protected static String result;

            @BeforeClass

public static void setup()

{

            wd = new FirefoxDriver();

            wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

}

            @Test

void Testcase1()

{

            wd.findElement(By.id("kwsch")).sendKeys("Red");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

Assert.assertEquals(result, "115");

}

            @Test

void Testcase2() {

            wd.findElement(By.id("kwsch")).sendKeys("Blue");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

            Assert.assertEquals(result, "13");

}

            @Test

void Testcase3() {

            wd.findElement(By.id("kwsch")).sendKeys("Yellow");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

            Assert.assertEquals(result, "27");

}

            @Test

void Testcase4() {

            wd.findElement(By.id("kwsch")).sendKeys("Purple");

            wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

            result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

            Assert.assertEquals(result, "10");

}

@AfterClass

public static void teardown() {

            wd.close();

            wd.quit();

}

}

for testing in browser

  @Test  
      public void testFirefox()  
              throws MalformedURLException, IOException {  
          DesiredCapabilities browser =  
              DesiredCapabilities.firefox();  
          testCodesCrud(browser);  
      }  
      @Test  
      public void testChrome()  
              throws MalformedURLException, IOException {  
          DesiredCapabilities browser =  
              DesiredCapabilities.chrome();  
          testCodesCrud(browser);  
      }  
       
      @Test  
      public void testOpera()  
              throws MalformedURLException, IOException {  
          DesiredCapabilities browser =  
              DesiredCapabilities.opera();  
          testCodesCrud(browser);