<repo_name>nehal19/SeleniumPractice<file_sep>/src/main/java/com/selenium/Scenario6.java
package com.selenium;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class Scenario6 {
	
	@Test(dataProvider = "credentials")
	public void checkCredentials(String username, String password) {
		System.out.println(username);
		System.out.println(password);
	}
	
	
	@DataProvider(name="credentials")
	public Object getData() {
		Object [][] data = new Object[2][2];
		data[0][0] = "username1";
		data[0][1] = "<PASSWORD>";
		data[1][0] = "username2";
		data[1][1] = "<PASSWORD>";
		return data;
	}
	

}
<file_sep>/src/main/java/com/selenium/Scenario3.java
package com.selenium;

import java.util.Iterator;
import java.util.Set;
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.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class Scenario3 {
	
WebDriver driver;
	
	@Before
	public void setup() {
		System.setProperty("webdriver.chrome.driver", "C:\\Users\\nehal.kadapatti\\"
				+ "Desktop\\chromedriver.exe");
		driver = new ChromeDriver();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}
	
	@Test
	public void medicalRecords() throws InterruptedException {
		driver.get("http://openclinic.sourceforge.net/openclinic/home/index.php");
		driver.findElement(By.linkText("Medical Records")).sendKeys(Keys.CONTROL,Keys.ENTER);
		
		Set<String> windows = driver.getWindowHandles();
		Iterator<String> it = windows.iterator();
		
		String parent = it.next();
		String child = it.next();
		
		driver.switchTo().window(child);
		driver.findElement(By.linkText("Search Patient")).click();
		WebElement options = driver.findElement(By.id("search_type"));
		Select selectFrom = new Select(options);
		Thread.sleep(2000);
		selectFrom.selectByVisibleText("First Name");
		driver.findElement(By.id("search_patient")).click();
		Thread.sleep(5000);
		
			
	}
	
	@Test
	public void popup() throws InterruptedException {
		driver.get("http://popuptest.com/goodpopups.html");
		driver.findElement(By.linkText("Good PopUp #3")).click();
		
		Thread.sleep(2000);
		
		Set<String> handler = driver.getWindowHandles();
		
		Iterator<String> it = handler.iterator();
		
		String parentWindowId = it.next();
		System.out.println("Parent Window:" + parentWindowId);
		
		String childWindowId = it.next();
		System.out.println("Child Window" + childWindowId);
		
		driver.switchTo().window(childWindowId);
		
		Thread.sleep(2000);
		
		System.out.println("ChildWindowpopupTitle" + driver.getTitle());
		driver.close();
		
		driver.switchTo().window(parentWindowId);
		Thread.sleep(2000);
		System.out.println("Parent Window Title:" + driver.getTitle());
		
	}
	@After
	public void teardown() {
		driver.quit();
	}

}
<file_sep>/src/main/java/com/selenium/Scenario8.java
package com.selenium;

import java.io.IOException;
import java.net.HttpURLConnection;

import java.net.URL;

import java.util.List;
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.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Scenario8 {
	WebDriver driver;
	@Before
	public void setup() {
		System.setProperty("webdriver.chrome.driver", "C:\\Users\\nehal.kadapatti\\"
				+ "Desktop\\chromedriver.exe");
		driver = new ChromeDriver();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}
	@After
	public void teardown() {
		driver.quit();
	}
	
	@Test
	public void brokenLinks() throws IOException {
		driver.get("http://www.zlti.com");
List<WebElement> links=driver.findElements(By.tagName("a"));
		
		System.out.println("Total links are "+links.size());
		
		System.setProperty("javax.net.ssl.trustStore", "D:\\certs");
		System.setProperty("javax.net.ssl.trustStorePassword", "<PASSWORD>");
		for(int i=0;i<links.size();i++)
		{
			WebElement ele= links.get(i);
				
			String url=ele.getAttribute("href");
			if(url!= null && (!url.contains("javascript"))) {
				verifyLinkActive(url);
			}
			
		}
	}
	public void verifyLinkActive(String linkUrl) throws IOException {
		try 
        {
           URL url = new URL(linkUrl);
           
           HttpURLConnection httpURLConnect=(HttpURLConnection)url.openConnection();
           
           httpURLConnect.setConnectTimeout(3000);  
           httpURLConnect.connect();
           
           if(httpURLConnect.getResponseCode()==200)
           {
               System.out.println(linkUrl+" - "+httpURLConnect.getResponseMessage());
            }
          if(httpURLConnect.getResponseCode()==HttpURLConnection.HTTP_NOT_FOUND)  
           {
               System.out.println(linkUrl+" - "+httpURLConnect.getResponseMessage() + 
            		   " - "+ HttpURLConnection.HTTP_NOT_FOUND);
            }
        } catch (Exception e) {
           System.out.println(e.getMessage());
        }

}
}
<file_sep>/src/main/resources/config.properties
browser = chrome

url = https://www.google.com

username = nehal

password = <PASSWORD>