I am trying to run my script using Selenium grid where I am able to parametrize the node IP address but not able to pass platform value.
Can anybody please help me to find out the solution, how to pass platform value through parameter.
I don't want to pass hardcode value like Windows or Mac or Vista. Need to pass via Excel.
code:
package package1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Test_excel_node_reading {
public class Universal_Music_grup {
WebDriver driver;
String baseUrl, nodeUrl;
@Test(dataProvider="UMG")
public void Universal_music_grp(String nodeUrl1) throws InterruptedException {
//driver.get(baseUrl);
baseUrl = "http://www.tedbaker.com/";
//nodeUrl = "http://192.168.163.52:5566/wd/hub//";
nodeUrl = nodeUrl1;
System.out.println(nodeUrl);
//nodeUrl = "http://192.168.102.42:5566/wd/hub//";
//nodeUrl = "http://192.168.160.247:5566/wd/hub//";
//nodeUrl = "http://192.168.162.83:5566/wd/hub//";
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(Platform.WIN10);
driver = new RemoteWebDriver(new URL(nodeUrl), capability);
driver.get("http://www.universalmusic.com");
driver.findElement(By.xpath(".//*[@id='main-menu-open']/span")).click();
Thread.sleep(1000);
driver.findElement(By.xpath(".//*[@id='main-menu-container']/div[2]/ul/li[3]/a/h3")).click();
driver.findElement(By.xpath(".//*[@id='section-items']/div/ul/li[1]/a/div")).click();
driver.findElement(By.xpath(".//*[@id='detail-main']/div[2]/ul/li/a")).click();
Thread.sleep(2000);
String MainWindow=driver.getWindowHandle();
System.out.println(MainWindow);
Set<String> s1=driver.getWindowHandles();
System.out.println(s1);
Iterator<String> i1=s1.iterator();
while(i1.hasNext())
{
String ChildWindow=i1.next();
System.out.println("test - "+ ChildWindow);
if(!MainWindow.equalsIgnoreCase(ChildWindow))
driver.switchTo().window(ChildWindow);
Thread.sleep(2000);
driver.findElement(By.xpath("html/body/div[3]/nav/div/div/button")).click();
WebElement Online_services=driver.findElement(By.xpath("html/body/nav/div/ul[1]/li[3]/a"));
WebElement Online_mastering=driver.findElement(By.xpath("html/body/div[1]/ul/li[2]/ul/li[2]/a"));
Online_mastering.click();
Thread.sleep(2000);
driver.findElement(By.xpath("html/body/div[4]/nav/div/div/button")).click();
driver.findElement(By.xpath("html/body/div[1]/ul/li[1]/ul/li[3]/ul/li[2]/a")).click();
driver.findElement(By.xpath("html/body/div[4]/main/div/div[1]/a[1]")).click();
driver.findElement(By.xpath(".//*[@id='contactForm']/textarea")).sendKeys("Nice songs");
driver.findElement(By.xpath(".//*[@id='contactForm']/input[5]")).sendKeys("Tina Malhotra");
driver.findElement(By.xpath(".//*[@id='contactForm']/input[6]")).sendKeys("tinamalhotra325@gmail.com");
}
}
logger.log(LogStatus.PASS, "Universal_music_grp,Book Music Session Test case passed");
}
@Test(priority=2)
public void Verify_Title () throws InterruptedException {
logger = extent.startTest("Universal_music_grp");
logger.log(LogStatus.INFO, "Launching the webdiste >>> http://www.universalmusic.com ");
driver.get("http://www.universalmusic.com");
String Expected_Title="Universal";
String ACtual_title=driver.getTitle();
driver.findElement(By.xpath("ABD")).click();
if(Expected_Title==ACtual_title)
{
logger.log(LogStatus.INFO, "Title of website is Universal Music group ");
}
else
System.out.println("Wrong Title");
}
@DataProvider(name="UMG")
public Object[][] loginData() throws BiffException, IOException {
Object[][] arrayObject = getExcelData("C:\\Java_practice\\UMG.xls","Sheet1");
return arrayObject;
}
public String[][] getExcelData(String fileName, String sheetName) throws BiffException, IOException {
String[][] arrayExcelData = null;
try
{
FileInputStream fs = new FileInputStream(fileName);
Workbook wb = Workbook.getWorkbook(fs);
Sheet sh = wb.getSheet(sheetName);
int totalNoOfCols = sh.getColumns();
int totalNoOfRows = sh.getRows();
System.out.println(totalNoOfCols);
System.out.println(totalNoOfRows);
arrayExcelData = new String[totalNoOfRows-1][totalNoOfCols];
for (int i= 1 ; i<totalNoOfRows; i++) {
for (int j=0; j<totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
return arrayExcelData;
}
}
}