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

attachments start with attachment0 for each test class #144

Closed
mgehlen opened this issue Oct 15, 2015 · 7 comments
Closed

attachments start with attachment0 for each test class #144

mgehlen opened this issue Oct 15, 2015 · 7 comments

Comments

@mgehlen
Copy link

mgehlen commented Oct 15, 2015

Hi,

I have now switched my mobile end-to-end tests completely to using BDD with JGiven and Appium as the actual test automation driver. I use testNG as a test runner and I separate my TestClasses alongside features.

My general structure is as follows:

public class MobileScenario extends ScenarioTest<GivenAppState, WhenActions, ThenAssertions>

MobileScenario uses testNG Dependency Injection to fetch the test configuration from maven ( i.e. test android or ios, which activity to start, which timeout to use, ...) and it defines some general tags for jGiven-reports.

  • AppiumDriver is initialized here using BeforeClass-Annotation from testNG and handed over to the stages using ProvidedScenarioState.
  • The AppiumDriver is also stopped using the AfterClass-Annotation from testNG to
public class LoginScenarioTest extends MobileScenario

This is an example for one of the actual test classes. It extends the MobileScenario mainly to get the Stages and the Tags. Then it just lists the scenarios to test and sometimes uses some DataProviders.

The interesting part in the stages might be the jGiven LifeCycle Annotations for ThenAssertions:

public class ThenAssertions extends Stage<ThenAssertions>
...
@AfterStage
    private void addScreenshotToReport() {

        Photographer photographer = new Photographer(appRunner.getDriver()) ;
        Attachment attachment = null;

        try {
            String timestamp = (new Timestamp(System.currentTimeMillis())).toString() ;
            attachment = Attachment.fromBinaryFile(photographer.takeScreenshot(), MediaType.PNG).withTitle("Screenshot_" + timestamp);
        } catch (IOException e) {
            e.printStackTrace();
        }

        currentStep.addAttachment(attachment) ;
    }

    @AfterScenario
    void resetAppRunner() throws IOException {

        appRunner.resetApp(this.port);
    }

So I reset the App after every scenario in order to give a clean and defined start for the next scenario so I don't need to worry if a scenario passed or failed in order for the next scenario to run properly.

Additionally I add a screenshot in AfterStage to my Scenario to show the last screen that appeared during a scenario to the report. This is the most interesting screen regadless of failure or success.

My problem now is:
each feature class starts the attachament from new with attachment0, so if I ...

  • run LoginScenarioTest taking 4 screenshots and adding one to four scenarios
  • and then run RegistrationScenarioTest taking 3 screenshots

The first 3 screenshots from LoginScenarioTest are overwritten, hence the final reports shows the screenshots from RegistrationScenarioTest in the scenarios for LoginScenarioTest. Using withTitle did not solve the problem, since it is only added to the tooltip.

Can you make the withTitle the actual name of the attachement for screenshots?
this way I can influence the filename all by myself during testing and get the correct screenshots in the report?

@janschaefer
Copy link
Contributor

that is definitely a bug. Thanks for reporting!

@janschaefer
Copy link
Contributor

Using withTitle for the filenames might not be that good, because I would have to escape/replace all special characters.

@janschaefer
Copy link
Contributor

I could introduce a new method withFilename if you think that this would be useful in your case.

@mgehlen
Copy link
Author

mgehlen commented Oct 15, 2015

thank you for the quick response - if my understanding is correct withFilename ist a very good way for me to go.

@ivan-masich
Copy link
Contributor

Hi,

Maybe it's better to use name of the test class (with package, for example com/example/TestClass/attachment0.txt) as sub-folders for grouping attachments, what do you think about this?

I have same problem, but in my case I'm using attachment to show all default application settings, so I have step "Given default settings" with "text" attachment to show 30+ settings and in this case usage of attachments is very nice way.

Generating for such attachment unique filename using method "withFilename" is not very nice as from my point of view because I have same step in 50+ tests.

@ivan-masich
Copy link
Contributor

By the way, "withFilename" is also nice to have, in this way we can give user-friendly name for attachments (considering that it must be unique in scope of one test class).

@janschaefer
Copy link
Contributor

Yes. By default a unique name for the attachments. Using subfolders would be an option. The withFilename would be optional.

janschaefer pushed a commit that referenced this issue Oct 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants