-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolutionOne.java
93 lines (76 loc) · 3.07 KB
/
SolutionOne.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.test;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class NewTest {
WebDriver driver;
@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.chrome.driver", "/home/ajit/Documents/selenium/chromedriver");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.google.com/maps/");
}
@Test
public void f() throws InterruptedException, IOException {
SoftAssert softassert = new SoftAssert();
WebElement searchBox = driver.findElement(By.id("searchboxinput"));
searchBox.sendKeys("Wankhede Stadium" + Keys.ENTER);
TakesScreenshot scrShot = ((TakesScreenshot) driver);
File s = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(s, new File("pic1.png"));
/*
* WebElement btnText=driver.findElement(By.xpath(
* "//*[@id=\"pane\"]/div/div[1]/div/div/div[2]/div[1]/div[1]/div[2]/div/div[2]/span[1]/span[1]/button"
* )); String words=btnText.getAttribute("value"); System.out.println("Btn"+
* words); Assert.assertEquals("stadium", words);
*/
WebElement btnText2 = driver.findElement(By.xpath("//span[contains(text(),'Wankhede Stadium Mumbai')]"));
String words2 = btnText2.getText();
System.out.println(words2);
softassert.assertEquals(words2,"Wankhede Stadium Mumbai");
softassert.assertAll();
System.out.println("Rating" + driver
.findElement(By.xpath("//span[@class='mapsConsumerUiSubviewSectionSharedStar__section-star-display']"))
.getText());
String title = driver.getTitle();
Assert.assertEquals(title, "Wankhede Stadium - Google Maps");
WebElement linkName = driver.findElement(By.xpath("//div[contains(text(),'mum')]"));
String links = linkName.getText();
System.out.println(links);
Assert.assertEquals("mumbaicricket.com", links);
WebElement add = driver.findElement(By.xpath("//div[contains(text(),'Vinoo')]"));
String address = add.getText();
System.out.println(address);
try {
WebElement phone = driver.findElement(By.xpath("//div[contains(text(),'022 2279 5500')]"));
if (phone.isDisplayed()) {
System.out.println("phone Number is displayed");
} else
System.out.println("phone Number is not displayed");
} catch (Exception e) {
System.out.println("Phone number element not present");
}
File s1 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(s1, new File("pic2.png"));
}
@AfterTest
public void afterTest() {
driver.quit();
}
}