package linkedIn_Interview;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.OutputType.*;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.screentaker.ViewportPastingStrategy;
public class Question1 {
static WebDriver d;
@BeforeMethod
public void setUp()
{
System.setProperty("webdriver.chrome.driver", "D:\\selenium_NEW_PRACTICE\\jars\\chromedriver_win32\\chromedriver.exe");
d=new ChromeDriver();
d.manage().window().maximize();
}
@Test
public void verifyLinkedInExam() throws InterruptedException, IOException
{
d.get("http://www.ia.ca");
getScreenshot();
//take the screenshot of the entire home page and save it to a png file
//Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(d);
//ImageIO.write(screenshot.getImage(), "PNG", new File("D:\\selenium_NEW_PRACTICE\\screenshots\\home"+System.currentTimeMillis()+".png"));
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
d.findElement(By.xpath("//span[contains(text(),'Loans')]")).click();
d.findElement(By.xpath("//a[contains(text(),'Mortgages')]")).click();
String mortgateTtl=d.getTitle();
Assert.assertEquals(mortgateTtl, "Mortgage - Mortage rates | iA Financial Group");
System.out.println("Verify title is pass : ");
JavascriptExecutor js=(JavascriptExecutor)d;
js.executeScript("window.scrollBy(0,700)", "");
System.out.println("page is scrolling to down : " );
d.findElement(By.xpath("//a[contains(text(),'Calculate your payments')]")).click();
JavascriptExecutor js1=(JavascriptExecutor)d;
js1.executeScript("window.scrollBy(0,700)", "");
System.out.println("page is scrolling to down : " );
WebElement slider = d.findElement(By.xpath("//div[contains(@class,'slider slider-horizontal')]"));
int width=slider.getSize().getWidth();
System.out.println("printing size width of slider : " + width);
Actions act=new Actions(d);
act.click(slider).build().perform();
Thread.sleep(1000);
for(int i=0;i<2;i++)
{
act.sendKeys(Keys.ARROW_RIGHT).build().perform();
}
for(int i=0;i<1;i++)
{
d.findElement(By.xpath("//*[@id='MiseDeFondPlus']")).click();
}
Select years=new Select(d.findElement(By.xpath("//*[@id='Amortissement']")));
years.selectByVisibleText("15 years");
Select timeFrequency=new Select(d.findElement(By.xpath("//*[@id='FrequenceVersement']")));
timeFrequency.selectByVisibleText("weekly");
d.findElement(By.xpath("//*[@id='TauxInteret']")).clear();
WebElement interestRate=d.findElement(By.xpath("//*[@id='TauxInteret']"));
interestRate.sendKeys("5");
d.findElement(By.xpath("//*[@id='btn_calculer']")).click();
Thread.sleep(1000);
String weekPayment=d.findElement(By.xpath("//*[@id='paiement-resultats']")).getText();
System.out.println("printin weekely payment info : " + weekPayment);
Assert.assertEquals(weekPayment, "$ 836.75");
}
@Test
public void getScreenshot()
{
//take the screenshot of the entire home page and save it to a png file
Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(d);
try
{
ImageIO.write(screenshot.getImage(), "PNG", new File("D:\\selenium_NEW_PRACTICE\\screenshots\\home"+System.currentTimeMillis()+".png"));
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
@AfterMethod
public void tearDown()
{
d.close();
System.out.println("closing bowser : ");
}
}
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.OutputType.*;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.screentaker.ViewportPastingStrategy;
public class Question1 {
static WebDriver d;
@BeforeMethod
public void setUp()
{
System.setProperty("webdriver.chrome.driver", "D:\\selenium_NEW_PRACTICE\\jars\\chromedriver_win32\\chromedriver.exe");
d=new ChromeDriver();
d.manage().window().maximize();
}
@Test
public void verifyLinkedInExam() throws InterruptedException, IOException
{
d.get("http://www.ia.ca");
getScreenshot();
//take the screenshot of the entire home page and save it to a png file
//Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(d);
//ImageIO.write(screenshot.getImage(), "PNG", new File("D:\\selenium_NEW_PRACTICE\\screenshots\\home"+System.currentTimeMillis()+".png"));
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
d.findElement(By.xpath("//span[contains(text(),'Loans')]")).click();
d.findElement(By.xpath("//a[contains(text(),'Mortgages')]")).click();
String mortgateTtl=d.getTitle();
Assert.assertEquals(mortgateTtl, "Mortgage - Mortage rates | iA Financial Group");
System.out.println("Verify title is pass : ");
JavascriptExecutor js=(JavascriptExecutor)d;
js.executeScript("window.scrollBy(0,700)", "");
System.out.println("page is scrolling to down : " );
d.findElement(By.xpath("//a[contains(text(),'Calculate your payments')]")).click();
JavascriptExecutor js1=(JavascriptExecutor)d;
js1.executeScript("window.scrollBy(0,700)", "");
System.out.println("page is scrolling to down : " );
WebElement slider = d.findElement(By.xpath("//div[contains(@class,'slider slider-horizontal')]"));
int width=slider.getSize().getWidth();
System.out.println("printing size width of slider : " + width);
Actions act=new Actions(d);
act.click(slider).build().perform();
Thread.sleep(1000);
for(int i=0;i<2;i++)
{
act.sendKeys(Keys.ARROW_RIGHT).build().perform();
}
for(int i=0;i<1;i++)
{
d.findElement(By.xpath("//*[@id='MiseDeFondPlus']")).click();
}
Select years=new Select(d.findElement(By.xpath("//*[@id='Amortissement']")));
years.selectByVisibleText("15 years");
Select timeFrequency=new Select(d.findElement(By.xpath("//*[@id='FrequenceVersement']")));
timeFrequency.selectByVisibleText("weekly");
d.findElement(By.xpath("//*[@id='TauxInteret']")).clear();
WebElement interestRate=d.findElement(By.xpath("//*[@id='TauxInteret']"));
interestRate.sendKeys("5");
d.findElement(By.xpath("//*[@id='btn_calculer']")).click();
Thread.sleep(1000);
String weekPayment=d.findElement(By.xpath("//*[@id='paiement-resultats']")).getText();
System.out.println("printin weekely payment info : " + weekPayment);
Assert.assertEquals(weekPayment, "$ 836.75");
}
@Test
public void getScreenshot()
{
//take the screenshot of the entire home page and save it to a png file
Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(d);
try
{
ImageIO.write(screenshot.getImage(), "PNG", new File("D:\\selenium_NEW_PRACTICE\\screenshots\\home"+System.currentTimeMillis()+".png"));
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
@AfterMethod
public void tearDown()
{
d.close();
System.out.println("closing bowser : ");
}
}
No comments:
Post a Comment