Unable to exceute navigate keyword | Selenium Forum
M
Posted on 05/09/2016
Could you please check why it was unable to navigate --navigate keyword.
It is opening browser but stopping to navigate .I checked paths and everything but unable to notice error and also unable to generate extent reports.I have been implemented twice but same mistake unable to navigate to URL.
or
Can I login on sunday.Can I share screen during sunday doubt clearing sessions.I have been trying this one since 3 weeks.Please let me know.

package com.Amazon.utility;

import java.util.Hashtable;

import org.junit.Assert;



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

import com.Amazon.data.AZConstant;
import com.Amazon.data.Axls_Reader;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class AKeywords {
ExtentTest test;
AAppKeywords app;
public AKeywords(ExtentTest test){
this.test=test;

}

public void ExceuteKeywords(Axls_Reader xls,String testCaseName,Hashtable<String, String> table){

int rows=xls.getRowCount(AZConstant.KEYWORD_SHEET);
for(int i=0;i<rows;i++){
String TCID=xls.getCellData(AZConstant.KEYWORD_SHEET,AZConstant.TCID_COL,i);
if(TCID.equalsIgnoreCase(testCaseName)){
String keyword= xls.getCellData(AZConstant.KEYWORD_SHEET,AZConstant.KEYWORD_COL,i);
String object= xls.getCellData(AZConstant.KEYWORD_SHEET,AZConstant.OBJECT_COL,i);
String key= xls.getCellData(AZConstant.KEYWORD_SHEET,AZConstant.DATA_COL,i);
String data=table.get(key);

test.log(LogStatus.INFO,"started exceuting "+keyword+object+data+key);

app=new AAppKeywords(test);

String result="";

if(keyword.equals("openBrowser"))
result=app.openBrowser(data);
else if(keyword.equals("navigate"))
result=app.navigate(object);


if(!result.equals(AZConstant.PASS)){
app.reportFailure(result);
Assert.fail(result);

}
}

}
}


public AAppKeywords getGenerickeywords(){
return app;
}

}



---------------------------------------------------------------------------------------------------------------------
package com.Amazon.utility;

import java.io.File;
import java.util.Date;

import com.Amazon.data.AZConstant;
import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;

public class AExtentManager {
private static ExtentReports extent;
public static ExtentReports getInstance(){
if(extent==null){
Date d=new Date();
String path=d.toString().replace(":","_").replace(" ","_")+".html";
extent=new ExtentReports(AZConstant.REPORT_PATH+path, true, DisplayOrder.NEWEST_FIRST);
extent.loadConfig(new File(System.getProperty("user.dir")+"\\ReportsConfig.xml"));
}
return extent;


}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.Amazon.utility;

import java.util.Hashtable;

import com.Amazon.data.AZConstant;
import com.Amazon.data.Axls_Reader;






public class ADataUtil {


public static Object[][] getData(Axls_Reader xls,String testCaseName) {

String SheetName="Data";

int testCaseStartRowNum=1;

while(!xls.getCellData(SheetName, 0,testCaseStartRowNum).equalsIgnoreCase(testCaseName)){
testCaseStartRowNum++;
}

int colStratRowNum=testCaseStartRowNum+1;
int dataStartRowNum=testCaseStartRowNum+2;
int rows=0;
while(!xls.getCellData(SheetName,0,dataStartRowNum+rows).equals("")){
rows++;
}
int cols=0;
while(!xls.getCellData(SheetName,cols,colStratRowNum).equals("")){
cols++;
}
Object[][] data=new Object[rows][1];
Hashtable<String, String> table=null;
int dataRow=0;
for(int i=dataStartRowNum;i<dataStartRowNum+rows;i++){
table=new Hashtable<String, String>();
for(int j=0;j<cols;j++){
String key= xls.getCellData(SheetName,j,colStratRowNum);
String value=xls.getCellData(SheetName,j,i);
table.put(key, value);
}
data[dataRow][0]=table;
dataRow++;
}
return data;
}

public static boolean isSuiteRunnable(Axls_Reader xls,String testCaseName){
String SheetName=AZConstant.TESTCASES_SHEET;
int rows=xls.getRowCount(SheetName);

for(int i=2;i<rows;i++){
String TCID=xls.getCellData(SheetName,AZConstant.TCID_COL,i);
if(TCID.equalsIgnoreCase(testCaseName)){
String runmode=xls.getCellData(SheetName,AZConstant.RUNMODE_COL,i);
if(runmode.equalsIgnoreCase("Y"))
return true;
else
return false;

}
}
return false;

}
}



---------------------------------------------------------------------------------------------------------------------------------------------------------
package com.Amazon.utility;
//C:\\Users\\sanja\\maven\\Amazon\\src\\test\\resources\\Aproject.properties")
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
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.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

import com.Amazon.data.AZConstant;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class AGenericKeywords {
WebDriver driver;
Properties prop;
ExtentTest test;
public AGenericKeywords(ExtentTest test){
this.test=test;
prop=new Properties();
try {
FileInputStream fis=new FileInputStream(System.getProperty("user.dir")+"\\src\\test\\resources\\Aproject.properties");
prop.load(fis);
} catch (Exception e) {
e.printStackTrace();
}
}
public String openBrowser(String browserType){
test.log(LogStatus.INFO, "openBrowser"+browserType);
if(browserType.equals("mozilla"))
driver=new FirefoxDriver();
else if(browserType.endsWith("chrome")){
System.getProperty("webdriver.chrome.driver","C:\\Users\\sanja\\Documents\\chromedriver_win32\\chromedriver.exe");
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
return AZConstant.PASS;
}

public WebElement getElement(String locatorKey){
WebElement e=null;
try{
if(locatorKey.endsWith("_xpath"))
driver.findElement(By.xpath(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_id"))
driver.findElement(By.id(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_linkText"))
driver.findElement(By.linkText(prop.getProperty(locatorKey)));
else
driver.findElement(By.name(prop.getProperty(locatorKey)));
}catch(Exception e1){
e1.printStackTrace();
reportFailure("unable to locat an elemnet"+locatorKey);

}
return e;
}

public String reportFailure(String message){
takeSreenshot();
test.log(LogStatus.FAIL,message);

return AZConstant.PASS;
}

public String takeSreenshot(){
Date d=new Date();
String path=d.toString().replace(":","_").replace("","_")+".png";
File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyDirectory(src,new File(AZConstant.REPORT_PATH+"\\screenshot"+path));
} catch (IOException e) {

e.printStackTrace();
}
test.log(LogStatus.INFO, test.addScreenCapture(path));
return AZConstant.PASS;
}

public String Click(String locatorKey){
test.log(LogStatus.INFO,"clciking on "+locatorKey);
getElement(locatorKey).click();
return AZConstant.PASS;
}

public String input(String locatorKey,String text){
test.log(LogStatus.INFO,"input on "+locatorKey+"sendkeys data is"+text);
getElement(locatorKey).sendKeys(text);
return AZConstant.PASS;
}
public String navigate(String URLKey){
test.log(LogStatus.INFO,"navigate to "+prop.getProperty(URLKey));
driver.get(prop.getProperty(URLKey));
return AZConstant.PASS;
}

public boolean isElementPresent(String locatorKey){
List<WebElement> e=null;
if(locatorKey.endsWith("_xpath"))
e=driver.findElements(By.xpath(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_id"))
e=driver.findElements(By.id(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_linkText"))
e=driver.findElements(By.linkText(prop.getProperty(locatorKey)));
else
e=driver.findElements(By.name(prop.getProperty(locatorKey)));
if(e.size()==0)
return false;
else
return true;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------
package com.Amazon.testcase;

import java.util.Hashtable;

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





import com.Amazon.data.AZConstant;
import com.Amazon.data.Axls_Reader;
import com.Amazon.utility.AAppKeywords;
import com.Amazon.utility.ADataUtil;
import com.Amazon.utility.AExtentManager;
import com.Amazon.utility.AKeywords;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class ALogin {
ExtentReports rep=AExtentManager.getInstance();
ExtentTest test;
String testName="LoginTest";
Axls_Reader xls=new Axls_Reader(System.getProperty("user.dir")+"\\src\\main\\java\\FlipKart1.xlsx");

@Test(dataProvider="getData")
public void doLogin(Hashtable<String, String> table){
test=rep.startTest(testName);
test.log(LogStatus.INFO, "strting the test"+testName);

if(!ADataUtil.isSuiteRunnable(xls,testName) || table.get(AZConstant.RUNMODE_COL).equalsIgnoreCase("N")){
test.log(LogStatus.SKIP, "skipping the test if runmode is no");
throw new SkipException("skipping the test if runmode is no");
}

AKeywords keyword=new AKeywords(test);
test.log(LogStatus.INFO,"exceuting the keywords"+keyword);
keyword.ExceuteKeywords(xls, testName, table);
keyword.getGenerickeywords().takeSreenshot();

}
@AfterTest
public void quit(){
if(rep!=null){
rep.endTest(test);
rep.flush();
}
}
@DataProvider
public Object[][] getData(){
return ADataUtil.getData(xls,testName);

}
}
-----------------------------------------------------------------------------------------------------------------------

M
Replied on 06/09/2016

i will be available next week. or you can contact Ashish.


M
Replied on 06/09/2016

Could you please let me know when you will be available next week at what timings to check my code or how should I contact Ashish to check my code.


M
Replied on 10/09/2016

Could you please let me know how you can help me to check my code.Thank you Ashish


M
Replied on 14/09/2016

What is the error which you get