Tuesday 22 November 2016

Selenium Live project - Automation Testing

Selenium live project with example


Many times while pursuing graduation we are suppose to make a project with team members in final semester or in any semester where we have difficulties in building such project and we take help from our seniors or any one who can help us.Let see and learn with below selenium live project and practice selenium online with ease.for any selenium training go to the homepage and get good content for starting with selenium webdriver.

So i am sharing with you all this selenium live project which analyze website and provide the output to the user in the console.
There are many selenium projects example out there which can help in start with selenium webdriver. We came across with one of the project where the expectation was to write a program which will analyze the website and provide the category that site is dealing with. lets say if we open cricbuzz then it must show that this is a sport website and category is cricket.
Likewise, if we open football website it should display in console that this is football website similarly for other sports website out there.

Selenium Live project for practice

Test case: You will provided with URL'S of 25 websites in a text file each URL in a separate line. Most of the URLs will be sports specific and some are not. Your program will access the websites and for each URL provide a result saying which URL is specific to which sport and if it is not sport specific the result will say NA.



Below is the selenium test automation script for the above test cases:



import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import org.openqa.selenium.By;

import org.openqa.selenium.NoSuchElementException;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class workingwithFiles {

 public static void main(String[] args) {

 WebDriver driver;

System.setProperty("webdriver.chrome.driver","d:/chromedriver.exe");

driver=new ChromeDriver();

 String s = "D:\\test.txt"; 

  

 FileReader f = null;

 BufferedReader br = null;

  

  try {

   String sCurrentLine;

   f = new FileReader(s);

   br = new BufferedReader(f);

   while ((sCurrentLine = br.readLine()) != null)

   {

     driver.get(sCurrentLine);

     String abc=driver.getPageSource();

     String bcd=driver.getTitle();

     String a=driver.findElement(By.xpath("//meta[@name='description']")).getAttribute("content");

     System.out.println(a);

     

     if(a.contains("cricket")||a.contains("Cricket")||bcd.contains("Cricket"))

    {

     System.out.println("Cricket");

     

     }

    if(a.contains("football")||a.contains("Football"))

    {

    System.out.println("football");

   

   

    }

   if(a.contains("tennis")||a.contains("Tennis")||bcd.contains("Tennis"))

    {

    System.out.println("tennis");

   

    }

    if(a.contains("archery")||a.contains("Archery")||bcd.contains("Archery"))

    {

    System.out.println("archery");

   

  

    }

   if(a.contains("hockey")||a.contains("Hockey")||bcd.contains("Hockey"))

    {

  

    System.out.println("hockey");

   }

   if(bcd.contains("HoopsHype")||a.contains("nba")||a.contains("wnba")||a.contains("Basketball")||a.contains("basketball")||bcd.contains("Basketball"))

    {

    System.out.println("Basketball");

   

    }

    if(a.contains("Rugby")||a.contains("rugby")||bcd.contains("Rubgy"))

    {

  

    System.out.println("Rugby");

   }

    if(a.contains("badminton")||a.contains("Badminton")||bcd.contains("badminton"))

    {

  

    System.out.println("badminton");

   }

   if(a.contains("cricket")!=true&&a.contains("Basketball")!=true&&a.contains("basketball")!=true&&a.contains("hockey")!=true&&a.contains("Hockey")!=true&&a.contains("archery")!=true&&a.contains("Archery")!=true

   &&a.contains("archery")!=true&&a.contains("Archery")!=true&&a.contains("tennis")!=true&&a.contains("Tennis")!=true&&bcd.contains("HoopsHype")!=true

   &&a.contains("football")!=true&&a.contains("Football")!=true&&a.contains("Cricket")!=true)

    {

    System.out.println("NA");

   

    }

   

   }

   driver.close();

   

   } catch (IOException e) {

     e.printStackTrace();

  }

  finally {

    try {

     if (txtReader != null)txtReader.close();

    } catch (IOException ex) {

     ex.printStackTrace();

    }

    }

  }

}


We will bring more selenium live projects to the website for automation testing



selenium live project 2019, selenium project

0 comments: