Error in script for testing 7000+ users login data present in excel using JXL

35 views
Skip to first unread message

Mohit Yadav

unread,
May 12, 2017, 7:25:05 AM5/12/17
to Selenium Users
Hi All

Am facing issues in a script where we have 7600 users login credentials of a website. Data is present in Excel file. Need to test weather all login credentials are valid or not.
Need help asap.
Am using JXL libraries, below is my code:

package automationFramework;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;



public class LoginTest {

WebDriver driver;
Workbook wb;
Sheet sh1;
int numrow;
String uname;
String password1;

@BeforeTest
public void Setup()

{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\mohitrao\\Desktop\\chromedriver.exe");

    WebDriver driver = new ChromeDriver();

   
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get("https://www.chiropractic.ca/");
    
   
}

@Test(dataProvider="testdata")
public void TestFireFox(String uname,String password1) throws InterruptedException

{

    Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath("html/body/div[1]/div[1]/section[1]/div/div[2]/form/ul/li[2]/a/span"));
action.moveToElement(we).build().perform();
Thread.sleep(5000);

driver.findElement(By.id("user-id")).clear();
driver.findElement(By.id("user-id")).sendKeys(uname);
driver.findElement(By.id("user-password")).clear();
driver.findElement(By.id("user-password")).sendKeys(password1);

driver.findElement(By.xpath("html/body/div[1]/div[1]/section[1]/div/div[2]/form/ul/li[2]/ul/li[4]/input[1]")).click();

}
/*

@AfterMethod
public void tearDown()
{
  driver.quit();
}

*/
@DataProvider(name="testdata")
public Object[][] TestDataFeed() throws BiffException, IOException 


{
// load workbook
wb=Workbook.getWorkbook(new File("C://Users//mohitrao//Desktop//testData.xls"));

// load sheet in my case I am referring to first sheet only
sh1= wb.getSheet(0);

// get number of rows so that we can run loop based on this
numrow= sh1.getRows();



// Create 2d array and pass row and columns
Object [][] facebookdata=new Object[numrow][sh1.getColumns()];

// This will run a loop and each iteration  it will fetch new row
for(int i=0;i<numrow;i++){


// Fetch first row username
facebookdata[i][0]=sh1.getCell(0, i).getContents();
// Fetch first row password
facebookdata[i][1]=sh1.getCell(1, i).getContents();


}
// Return 2d array object so that test script can use the same
return facebookdata;
}



 @AfterTest
 
public void QuitTC(){

// close browser after execution
driver.quit();
}








Here is Error log:

Starting ChromeDriver 2.29.461591 (62ebf098771772160f391d75e589dc567915b233) on port 28366
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
May 12, 2017 4:43:39 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
FAILED CONFIGURATION: @AfterTest QuitTC
java.lang.NullPointerException
at automationFramework.LoginTest.QuitTC(LoginTest.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.TestRunner.afterRun(TestRunner.java:958)
at org.testng.TestRunner.run(TestRunner.java:606)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

FAILED: TestFireFox("dickieabbott", "cca49050")
java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
at org.openqa.selenium.interactions.Actions.<init>(Actions.java:71)
at automationFramework.LoginTest.TestFireFox(LoginTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
    Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================



If i commented Quit method then this error show:

Starting ChromeDriver 2.29.461591 (62ebf098771772160f391d75e589dc567915b233) on port 24095
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
May 12, 2017 4:48:29 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
FAILED: TestFireFox("dickieabbott", "cca49050")
java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
at org.openqa.selenium.interactions.Actions.<init>(Actions.java:71)
at automationFramework.LoginTest.TestFireFox(LoginTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


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

⇜Krishnan Mahadevan⇝

unread,
May 12, 2017, 7:31:09 AM5/12/17
to seleniu...@googlegroups.com

You are having a NullPointerException. Have you tried setting debug points to find out what is causing it ?

Skimming through your code I see two fixes :

1. Replace @BeforeTest with @BeforeMethod
2. Change the line "WebDriver driver = new ChromeDriver();" to "driver = new ChromeDriver();" in your setup method.

And then try again.


----------------------------------------------------------------
This e-mail is confidential. If you are not an intended recipient, please delete this e-mail and notify us immediately. Any unauthorized use or disclosure is prohibited.               
Copyright (c) 2017  108 ideaspace inc.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/078cdc9c-b8ed-477f-ab0d-aea941fcae6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Mohit Yadav

unread,
May 12, 2017, 1:13:19 PM5/12/17
to seleniu...@googlegroups.com
thanks Krishnan it works now :)

Thanks & regards
Mohit
Test Engineer


Skype: Mohit.108ideaspace
LinkedIn: 

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/CputV3c3A3U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANikZLnxv8QnskU5%2BVqzuPRm2_KLS8Fp4RrxzMFGoAbOhaZ6SA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages