Zoho: data not filling into Company and Last Name field | Selenium Forum
C
Cheong Kah Seng Posted on 17/11/2020

Failed to type data to the Company and Last Name field after adding a new lead. The path with problem had been bolded. Is the "leadCompany_xpath" and "leadLastName_xpath" valid? If valid, why the data not filling in? If not, do sir or anyone have any solution?Thanks

LeadTest.java 

package com.qtpselenium.zoho.project.testcases;

import java.io.IOException;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.qtpselenium.zoho.project.base.BaseTest;

public class LeadTest extends BaseTest{


@Test(priority=1)
public void createLeadTest() throws IOException, InterruptedException {
test = rep.startTest("CreateLeadTest");
init();
openBrowser("Chrome");
navigate("appurl");

doLogin(prop.getProperty("username"), prop.getProperty("password"));
click("crmlink_xpath");
wait(1);
click("leadsTab_xpath");
wait(1);
click("plus_btn_xpath");
wait(1);
click("newLead_dropDown_xpath");
wait(3);
type("leadCompany_xpath", "Samsung");
type("leadLastName_xpath", "Wilson");
click("leadSaveButton");

//validate



}

@Test(priority=2,dependsOnMethods= {"createLeadTest"})
public void convertLeadTest() {
Assert.fail();
}

@Test(priority=3,dependsOnMethods= {"createLeadTest", "convertLeadTest"})
public void deleteLeadAccountTest() {

}


}

BaseTest.java

package com.qtpselenium.zoho.project.base;

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.JavascriptExecutor;
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.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.asserts.SoftAssert;

import com.qtpselenium.zoho.project.util.ExtentManager;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class BaseTest {
//want to make some reusable function in basetest class
public WebDriver driver;
public Properties prop;
public ExtentReports rep = ExtentManager.getInstance();
public ExtentTest test;
//public SoftAssert softAssert = new SoftAssert();

public void init() throws IOException {
//init the prop file
if(prop==null) {
prop=new Properties();
FileInputStream fs = new FileInputStream(System.getProperty("user.dir") + "\\src\\test\\resources\\projectconfig.properties");
prop.load(fs);
}
}

public void openBrowser(String bType) throws IOException {

//--System.out.println(prop.getProperty("appurl"));

//System.out.println(System.getProperty("user.dir"));
test.log(LogStatus.INFO, "Opening " + bType + " browser ");
if(bType.equals("Mozilla")) {
System.setProperty("webdriver.gecko.driver", "C:\\webdrivers\\geckodriver.exe");
driver = new FirefoxDriver();
}
else if(bType.equals("Chrome")) {
System.setProperty("webdriver.chrome.driver", prop.getProperty("chromedriver_exe"));
driver = new ChromeDriver();
}
else if(bType.equals("IE")) {
System.setProperty("webdriver.ie.driver", prop.getProperty("iedriver_exe"));
driver = new InternetExplorerDriver();
}
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//driver.manage().window().maximize(); //Unusable
test.log(LogStatus.INFO, bType + " browser opened successfully");

}

public void navigate(String urlKey) {
test.log(LogStatus.INFO, "Navigating to " + prop.getProperty(urlKey));
driver.get(prop.getProperty(urlKey));
}

/**
public void click(String xpathEleKey) {
driver.findElement(By.xpath(prop.getProperty(xpathEleKey))).click();
}

public void type(String xpathEleKey, String dataKey) {
driver.findElement(By.xpath(prop.getProperty(xpathEleKey))).sendKeys(prop.getProperty(dataKey));
}
* @throws IOException
**/

public void click(String locatorKey) throws IOException {
test.log(LogStatus.INFO, "Clicking on " + locatorKey);
getElement(locatorKey).click();
test.log(LogStatus.INFO, "Clicked successfully on " + locatorKey);
}

public void type(String locatorKey, String data) throws IOException {
test.log(LogStatus.INFO, "Typing in " + locatorKey + ". Data - " + data);
getElement(locatorKey).sendKeys(data);
test.log(LogStatus.INFO, "Typed successfully on " + locatorKey);
}

//finding element and returning it
public WebElement getElement(String locatorKey) throws IOException {
WebElement e = null;
try {
if(locatorKey.endsWith("_id")) {
e = driver.findElement(By.id(prop.getProperty(locatorKey)));
}
else if(locatorKey.endsWith("_name")) {
e = driver.findElement(By.name(prop.getProperty(locatorKey)));
}
else if(locatorKey.endsWith("_xpath")) {
e = driver.findElement(By.xpath(prop.getProperty(locatorKey)));
}
else {
reportFailure("Locator not correct - " + locatorKey);
Assert.fail("Locator not correct - " + locatorKey);
}
}catch(Exception ex) {
//fail the test and report the error
reportFailure(ex.getMessage());
ex.printStackTrace();
Assert.fail("Failed the test - " + ex.getMessage());
}
return e;
}

/********************Validations************************/
public boolean verifyTitle() {
return false;
}

public boolean isElementPresent(String locatorKey) throws IOException {
List<WebElement> elementList = null;
try {
if(locatorKey.endsWith("_id")) {
elementList = driver.findElements(By.id(prop.getProperty(locatorKey))); //use findElements
}
else if(locatorKey.endsWith("_name")) {
elementList = driver.findElements(By.name(prop.getProperty(locatorKey))); //use findElements
}
else if(locatorKey.endsWith("_xpath")) {
elementList = driver.findElements(By.xpath(prop.getProperty(locatorKey))); //use findElements
}
else {
reportFailure("Locator not correct - " + locatorKey);
Assert.fail("Locator not correct - " + locatorKey);
}
}catch(Exception ex) {
//fail the test and report the error
reportFailure("Locator not correct - " + locatorKey);
Assert.fail("Locator not correct - - " + locatorKey);
}
if(elementList.size()==0)
return false;
else
return true;
}

public boolean verifyText(String locatorKey, String expectedTextKey) throws IOException {
String actualText = getElement(locatorKey).getText().trim();
String expectedText=prop.getProperty(expectedTextKey);
if(actualText.equals(expectedText))
return true;
else
return false;
}

/********************Reporting**************************/
public void reportPass(String msg) {
test.log(LogStatus.PASS, msg);
}

public void reportFailure(String msg) throws IOException {
test.log(LogStatus.FAIL, msg);
takeScreenshot();
Assert.fail(msg);
}

public void takeScreenshot() throws IOException{
Date d=new Date();
String filename=d.toString().replace(":", "_").replace(" ", "_");
//store screenshots in that file
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"\\screenshots\\"+filename+".jpg"));

//put screenshot file in reports
test.log(LogStatus.INFO, "Screenshot-> " + test.addScreenCapture(System.getProperty("user.dir")+"\\screenshots\\"+filename+".jpg"));
}

//Reusable, but only for applications

public void waitForPageToLoad() {
JavascriptExecutor js=(JavascriptExecutor)driver;
String state = (String)js.executeScript("return document.readyState");

while(!state.equals("complete")) {
wait(2);
state = (String)js.executeScript("return document.readyState");

}
}

public void wait(int timeToWaitInSec) {
try {
Thread.sleep((timeToWaitInSec * 1000));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/*******************App functions
* @throws InterruptedException *********************/
public boolean doLogin(String username, String password) throws IOException, InterruptedException{
test.log(LogStatus.INFO, "Trying to login with " + username + ", " + password);
click("loginLink_xpath");

wait(1);

type("loginid_xpath", username);
wait(2); //Thread.sleep (wait() method) is important here to wait for the next button ready
click("loginIdNext_btn_xpath");
type("password_xpath", password);
click("pwSignIn_btn_xpath");




if(isElementPresent("crmlink_xpath")) {
test.log(LogStatus.INFO, "Login Success");

return true;
}
else {
test.log(LogStatus.INFO, "Login Failed");
return false;
}
}

}

projectconfig.properties

#Default Login Credentials
username=xxx@gmail.com
password=xxxxx


#Paths
xls_path=C:\\Sample Projects\\Eclipse\\Data_Driven_Zoho_v1\\Zoho.xlsx
#System.getProperty("user.dir") + "\\Data.xlsx\\"
iedriver_exe=C:\\webdrivers\\IEDriverServer.exe
chromedriver_exe=C:\\webdrivers\\chromedriver.exe
appurl=http://zoho.com

#Links
loginLink_xpath=//a[@class='zh-login']
crmlink_xpath=//*[@id="zl-myapps"]/div[1]/div[6]/div/a/span
leadsTab_xpath=//*[@id="mainMenuTabDiv"]/crm-menu/div[1]/crm-tab/div[2]/div[2]/a


#Text fields
loginid_xpath=//*[@id="login_id"]
password_xpath=//*[@id="password"]

#Buttons
loginIdNext_btn_xpath=//button[@id='nextbtn']/span
pwSignIn_btn_xpath=//*[@id="nextbtn"]/span
plus_btn_xpath=//*[@id="table_row_1"]/lyte-td[2]/span[1]/link-to/button
newLead_dropDown_xpath=//*[@id="submenu_Leads"]
leadSaveButton=//*[@id="saveLeadsBtn"]

#Text Fields
leadCompany_xpath=//input[@id="Crm_Leads_COMPANY"] //this xpath failed to work #1
leadLastName_xpath=//input[@id="Crm_Leads_LASTNAME"] //this xpath failed to work #2

 

 


A
Ashish Replied on 18/11/2020

Hello,

What is the roor which you are getting?


C
Cheong Kah Seng Replied on 18/11/2020

Following 2 lines not working:

type("leadCompany_xpath", "Samsung");
type("leadLastName_xpath", "Wilson");

Their xpath:

leadCompany_xpath=//input[@id="Crm_Leads_COMPANY"] //this xpath failed to work #1
leadLastName_xpath=//input[@id="Crm_Leads_LASTNAME"] //this xpath failed to work #2

Thanks

 


A
Ashish Replied on 19/11/2020

Can you paste the exception which you are getting?


C
Cheong Kah Seng Replied on 19/11/2020

Here is the error code:

[RemoteTestNG] detected TestNG version 7.0.0
Nov 18, 2020 12:41:25 AM com.relevantcodes.extentreports.ExtentReports loadConfig
WARNING: Unable to perform report configuration. The file C:\Sample Projects\Eclipse\TestNG Datadriven Framework Zoho(3rd attempt)\Data_Driven_Zoho_v1\ReportsConfig.xml was not found.
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager).
log4j:WARN Please initialize the log4j system properly.
Starting ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378}) on port 25756
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
FAILED: createLeadTest
java.lang.AssertionError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="submenu_Leads"]"}
(Session info: chrome=86.0.4240.198)
(Driver info: chromedriver=86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378}),platform=Windows NT 10.0.19041 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.26 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '14.0.2'
Driver info: driver.version: RemoteWebDriver
at org.testng.Assert.fail(Assert.java:97)
at com.qtpselenium.zoho.project.base.BaseTest.reportFailure(BaseTest.java:174)
at com.qtpselenium.zoho.project.base.BaseTest.getElement(BaseTest.java:118)
at com.qtpselenium.zoho.project.base.BaseTest.click(BaseTest.java:89)
at com.qtpselenium.zoho.project.testcases.LeadTest.createLeadTest(LeadTest.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

SKIPPED: convertLeadTest
java.lang.Throwable: Method LeadTest.convertLeadTest()[pri:2, instance:com.qtpselenium.zoho.project.testcases.LeadTest@563e4951] depends on not successfully finished methods
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:99)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

SKIPPED: deleteLeadAccountTest
java.lang.Throwable: Method LeadTest.deleteLeadAccountTest()[pri:3, instance:com.qtpselenium.zoho.project.testcases.LeadTest@563e4951] depends on not successfully finished methods
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:99)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
Default test
Tests run: 3, Failures: 1, Skips: 2
===============================================


===============================================
Default suite
Total tests run: 3, Passes: 0, Failures: 1, Skips: 2
===============================================


C
Cheong Kah Seng Replied on 19/11/2020

Kindly take note on the update on this projectconfig.properties file: 

#Default Login Credentials
username=xxxxx@gmail.com //Not a usable email
password=xxxx //Not a correct password


#Paths
xls_path=C:\\Sample Projects\\Eclipse\\TestNG Datadriven Framework Zoho(3rd attempt)\\Data_Driven_Zoho_v1\\Zoho.xlsx
#System.getProperty("user.dir") + "\\Data.xlsx\\"
iedriver_exe=C:\\webdrivers\\IEDriverServer.exe
chromedriver_exe=C:\\webdrivers\\chromedriver.exe
appurl=http://zoho.com

#Links
loginLink_xpath=//a[@class='zh-login']
crmlink_xpath=//*[@id="zl-myapps"]/div[1]/div[6]/div/a/span
leadsTab_xpath=//*[@id="mainMenuTabDiv"]/crm-menu/div[1]/crm-tab/div[2]/div[2]/a


#Text fields
loginid_xpath=//*[@id="login_id"]
password_xpath=//*[@id="password"]

#Buttons
loginIdNext_btn_xpath=//button[@id='nextbtn']/span
pwSignIn_btn_xpath=//*[@id="nextbtn"]/span
plus_btn_xpath=//*[@id="table_row_1"]/lyte-td[2]/span[1]/link-to/button
newLead_dropDown_xpath=//*[@id="submenu_Leads"]
leadSaveButton=//*[@id="saveLeadsBtn"]

#//button[@id='nextbtn']

#Email composing elements
compose_btn_xpath=//*[@id=":3c"]/div/div
recipient_xpath=//*[@id=":7f"]

#Text Fields
leadCompany_xpath=//input[@id="Crm_Leads_COMPANY"]
leadLastName_xpath=//input[@id="Crm_Leads_LASTNAME"]

/html/body/div[14]/div[12]/form/div/div[7]/div[2]/div/div[2]/div[1]/div[2]/input
/html/body/div[14]/div[12]/form/div/div[7]/div[2]/div/div[2]/div[2]/div[2]/input
#Title

 

 


A
Ashish Replied on 20/11/2020

java.lang.AssertionError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="submenu_Leads"]"}

This is the exact error.

Can you please check if you are able to find the element with this xpath //*[@id="submenu_Leads"]

Or if it is existing


C
Cheong Kah Seng Replied on 20/11/2020

It works, thanks a lot. Appreciate your effort. #StaySafe


Related Posts