Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Conversation

@annabudziszewska
Copy link

Description

Analytics module, which supports the Adobe Analytics and the Google Analytics solutions

Motivation and Context

In order to easily create automated analytics tests
As a team member
I want to use the dedicated Bobcat solution

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code styleguide of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

title: "Module: Analytics"
---

{% include under-construction.html %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here? Is it still under construction?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch :)

## Setup

We used the gradle template so we have much of the job already done.
All we need to to is to add the analytics module to our [runmode]({{site.baseurl}}/docs/modules/core/runmodes/) in default.yaml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the dependency be added to build.gradle too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. The full setup description is in the docs/_docs/modules/analytics.md so I will just link this doc here

```yaml
google.analytics.datalayer: [name]
```
The default values are defined as follows:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that if I don't configure it then these will be the values assigned to these properties?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it wouldn't. I will fix that

getActual(),
JSONCompareMode.LENIENT);
} catch (JSONException e) {
e.printStackTrace();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline character would be nice, because currently the error log looks like this:

Data Layer is incorrect page.country
Expected: ford-g1b
got: ford-gb
; page.pageName
Expected: braxDnd:home
got: brand:home

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

Copy link
Contributor

@mkrzyzanowski mkrzyzanowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check https://github.com/Cognifide/bobcat/blob/master/CONTRIBUTING.md and apply correct formatting.

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's newer version available, 2.6.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

private static final String CFG_PATH = "analytics/datalayers/";

@Inject
private WebDriver webDriver;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no other use for WebDriver itself here, Instead of injecting it and casting it to JavascriptExecutor later on, you can inject the executor itself :).

private static final String CFG_PATH = "analytics/datalayers/";

@Inject
private WebDriver webDriver;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no other use for WebDriver itself here, Instead of injecting it and casting it to JavascriptExecutor later on, you can inject the executor itself :).

getActual(),
JSONCompareMode.LENIENT);
} catch (JSONException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logger here

*/
package com.cognifide.qa.bb.analytics;

public interface Analytics {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JavaDoc here


/**
* Compares data layer retrieved from the page with the expected one
* @param expectedData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe the param more explicitly

} catch (IOException | URISyntaxException e) {
LOG.error("Could not read JSON file: " + fileName);
}
throw new IllegalStateException("JSON file could not be read");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be thrown directly in the catch clause, without logging the error (pass the initial stacktrace: IllegalStateException("...". e))

import com.cognifide.qa.bb.modules.CoreModule;
import com.google.inject.AbstractModule;

public class TestModule extends AbstractModule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this AnalyticsTestModule - we have too many test modules flying around already :)


@Test
public void shouldSetDataLayerForHomepageLoad() {
webDriver.get("https://solutionpartners.adobe.com/home.html");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on external sites seems a bit risky in terms of stability - could we somehow mimic this behaviour on a dummy page locally?


@Test
public void shouldSetDataLayerForHomepageLoad() {
webDriver.get("https://www.cognifide.com/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

- unit tests in bb-analytics module had incorrect endlines
- domain changed on the dependent test page (cognifide.github.io -> tech.cognifide.com) - we need to address it in the future ;)
- yet another change in external resource caused tests to fail - need to remove it
@mkrzyzanowski mkrzyzanowski merged commit 26455be into master Apr 23, 2020
@mkrzyzanowski mkrzyzanowski deleted the analytics2 branch April 23, 2020 03:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants