Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the Loading Data using Excel wiki up to date? #67

Open
markwinspear opened this issue Jun 17, 2015 · 11 comments
Open

Is the Loading Data using Excel wiki up to date? #67

markwinspear opened this issue Jun 17, 2015 · 11 comments

Comments

@markwinspear
Copy link

Hi

I notice that the last updated date on this wiki page is November 2012 and signs-off with .. "Very soon, and I mean really very soon, we will be supporting defining data in terms of Excel Objects. So a user can define a Date object as a value of the box in the given column and easyTest will take care of properly interpreting them and providing the right value to your test case.
I will keep you posted as and when that gets available."

Has the functionality changed and is the wiki page up to date please?

@anujgandharv
Copy link
Member

Hi Mark,
So, My apologies. The Wiki page is a bit outdated. but, EasyTest does support converting values specified in excel to proper Objects like Date. This is supported in slightly different manner though.

For eg. you can have a filed in your Excel sheet with a date value like this : 16-06-1980. You can then use the Format annotation to specify the format of the date in your test class. EasyTest will then convert the string value in the excel sheet to a Date using the specified format. Format annotation is supported for Date, Time and DateTime objects.

For other primitive objects like Integer, Boolean, Short, Long, Float etc it is taken care automatically for you.

If you want the value specified in the excel to be converted to some specific Object (for example to an instance of a class custom written), you can use the
Converters annotation to specify how the string value be converted to a specific object. You need to extend the (AbstractConverter)[https://github.com/EaseTech/easytest-core/blob/master/src/main/java/org/easetech/easytest/converter/AbstractConverter.java] class. If you want I can provide you with some examples of converting the string value to a specific Java class.

Does this answer your question? Is there any specific functionality that you are looking at, which I can help you with?

@markwinspear
Copy link
Author

Hi Anuj. Thanks for the quick reply! I don't actually have any use cases for that particular scenario at present, I was just evaluating against some possible future requirements. All of the items I am loading in are Excel files and all cell values are Strings (which makes life easier)

Essentially, I am trying to use EasyTest to load in some login details from an excel file along with an expected result and then re-run a login @test using all data rows.

The issues I am having so far are:

  1. xlsx files 'seem' unsupported? An exception is thrown - perhaps because HSSF from apache.poi is being used rather than XSSF?
  2. If changing the file extension to .xls, I get the following exception:

java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
.....

I have my class setup as follows. Is there anything obviously wrong that you can see?

package tests;

import org.easetech.easytest.loader.LoaderType;
import org.easetech.easytest.runner.DataDrivenTestRunner;
import org.junit.Test;
import org.junit.Before;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import pageobjects.Login;
import tests.groups.Smoke;
import utility.ExcelUtils;
import utility.Constant;

import org.easetech.easytest.annotation.Param;
import org.easetech.easytest.annotation.DataLoader;

import static org.junit.Assert.*;

@RunWith(DataDrivenTestRunner.class) //added for Data driven testing using Easytest
@dataloader(filePaths = {"C:\Users\winspearm\Desktop\testData.xls"}, loaderType = LoaderType.EXCEL)
public class TestLogin extends Base {

private Login login;
private String title;

@Before
public void setUp() {
    login = new Login(driver);
 }

@Test
@Category(Smoke.class)
public void succeeded() {
    login.with("tomsmith","SuperSecretPassword!");
    assertTrue("success message not present", login.successMessagePresent());
}

@Test
@Category(Smoke.class)
public void failed() {
    login.with("tomsmith","bad password");
    assertTrue("failure message wasn't present after providing an incorrect password", login.failureMessagePreeent());

}

@Test
@Category(Smoke.class)
public void dataProvisioning(@Param(name="username")String username, @Param(name = "password") String password, @Param(name="expectedResult")String expectedResult) throws Exception {

 //   ExcelUtils.setExcelFile(Constant.path_TestData + Constant.file_testData,"login");
 //   String username = ExcelUtils.getCellData(1,1);          //zero-based indexing
 //   String password = ExcelUtils.getCellData(1,2);
 //   String expectedResult = ExcelUtils.getCellData(1,3);
    login.with(username, password);

    switch (expectedResult) {
        case "Success":
            assertTrue("success message not present", login.successMessagePresent());
            break;
        case "Failure":
            assertTrue("failure message wasn't present after providing an incorrect password", login.failureMessagePreeent());
            break;
        default:
            ExcelUtils.SetCellData("Exception",1,4);
            throw new IllegalArgumentException("Expected either Success or Failure but found " + expectedResult );
    }
}

}

Thanks in advance for any help you could provide. I am not a developer by trade, I am a tester who is self-taught in java so forgive me if the answer is somewhat obvious to a professional.

@anujgandharv
Copy link
Member

Hi Mark, As you mentioned XLSX is indeed not supported currently for the reason you mentioned. I would be more than happy to merge a pull request supporting XSLX.
From what you have sent above, I believe everything is OK. Can you share the XLS file with me so that I can try running it locally to see what may be the issue.

BTW, which version of EasyTest are you using?

@markwinspear
Copy link
Author

Sure - i've emailed it to you now (as I could not attach it). It only has one row with some dummy data in it at the moment until I can get my setup working and expand it out. I've also uploaded the whole project to github now... https://github.com/markwinspear/seleniumguidebook-examples/ (Note - this expanded from implementing some examples in the Selenium guidebook (hence the legacy name), but has been expanded out since then)

I'm referencing version 1.3.2 of easytest-core in my maven pom.

I wouldn't know where to start regarding the pull request and modification to support xslx unfortunately - I would certainly be willing to do this otherwise as I think easytest is a great solution to data provisioning.

@anujgandharv
Copy link
Member

Hey Mark,
I can guide you to the process of contributing to EasyTest. Its a simple
process.

Before that, lets get you started with EasyTest. One thing I noticed is
that you are using JUnit 4.11. Easytest is written on JUnit 4.10. Could you
try using 4.10 version and see if that works. In the mean time I will try
to import your code base in my lab and see what may be the issue.

Thanks,
Anuj Kumar

On Thu, Jun 18, 2015 at 11:17 AM, markwinspear [email protected]
wrote:

Sure - i'll emailed it to you shortly (as I could not attach it). It only
has one row with some dummy data in it at the moment until I can get my
setup working and expand it out. I've also uploaded the whole project to
github now... https://github.com/markwinspear/seleniumguidebook-examples/
(Note - this expanded from implementing some examples in the Selenium
guidebook (hence the legacy name), but has been expanded out since then)

I'm referencing version 1.3.2 of easytest-core in my maven pom.

I wouldn't know where to start regarding the pull request and modification
to support xslx unfortunately - I would certainly be willing to do this
otherwise as I think easytest is a great solution to data provisioning.


Reply to this email directly or view it on GitHub
#67 (comment).

@markwinspear
Copy link
Author

Thanks for that Anuj.
Changing the version of Junit in the POM still results in the same error.

Regarding the XLSX issue, I've cloned and branched your code. it looks like 'SS' can be used in place of 'XSSF' and 'HSSF' to enable either to be used, however, your code already uses 'SS' in most places - I've made a few tweaks - just not sure how to get them to you to review using git (I'm using Intellij)

@anujgandharv
Copy link
Member

Hey mark,
You've cloned the wrong project. Please clone Easytest Core : https://github.com/EaseTech/easytest-core

@markwinspear
Copy link
Author

Apologies, I will do that now

@markwinspear
Copy link
Author

Ok, I've commited the changes to ExcelDataLoader that I think will work (I attempted to run all the tests but there are errors elsewhere unrelated to the changes I made).
I get a fatal error when trying to push this as new branch from IntelliJ however:
"Push failed: Failed with error: fatal: unable to access 'https://github.com/EaseTech/easytest-core.git/": The requested URL returned error: 403

@anujgandharv
Copy link
Member

Hi Mark,
Push to easytest-core on Easetech will fail because you do not have access
to write to it.
Just create a branch from EasyTest Core, commit to that branch and then
issue a Pull Request to me. I will then review the changes and merge them
to EasyTest Core.

I am glad you are taking out time to commit to easyTest. I appreciate it.

Thanks,
Anuj Kumar

On Thu, Jun 18, 2015 at 3:06 PM, markwinspear [email protected]
wrote:

Ok, I've commited the changes to ExcelDataLoader that I think will work (I
attempted to run all the tests but there are errors elsewhere unrelated to
the changes I made).
I get a fatal error when trying to push this as new branch from IntelliJ
however:
"Push failed: Failed with error: fatal: unable to access '
https://github.com/EaseTech/easytest-core.git/": The requested URL
returned error: 403


Reply to this email directly or view it on GitHub
#67 (comment).

@markwinspear
Copy link
Author

No problems. It's been a nice challenge to do this in github for the first time! I'm unable to create a pull request containing the new branch I created as I can only select existing branches. I've tried from both Intellij and from the github windows gui with the same result!

I have emailed the file to you with a list of changes made - there were only a few

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants