Skip to content

Commit

Permalink
feat(java): ✨ added test data handling from excel file (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB authored Dec 6, 2023
1 parent fbe45f1 commit 23e3624
Show file tree
Hide file tree
Showing 41 changed files with 5,624 additions and 11,004 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body:
attributes:
label: Issue Version
description: 🔢 What version of the framework is this bug related to?
placeholder: v0.18.0
placeholder: v0.19.0
validations:
required: true

Expand Down
12 changes: 7 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ updates:
reviewers:
- 'boyka-core'
schedule:
interval: 'monthly'
interval: 'weekly'
timezone: 'Asia/Calcutta'
groups:
dependencies:
dependency-type: 'production'
dev-dependencies:
dependency-type: 'development'
major:
update-types: ['major']
minor:
update-types: ['minor']
patch:
update-types: ['patch']

- package-ecosystem: 'maven'
directory: '/core-java'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/_test-core-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jobs:
${{ github.workspace }}/core-java/target
${{ github.workspace }}/core-java/logs
${{ github.workspace }}/core-java/screenshots
${{ github.workspace }}/core-java/videos
- name: Upload reports folder
uses: actions/upload-artifact@v3
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/test-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,18 @@ jobs:
emulator-arch: x86
emulator-target: aosp_atd

test-mobile-web:
needs:
- check-cloud
uses: ./.github/workflows/_test-core-java.yml
with:
runs-on: macos-latest
suite-name: testng-mobile-web
run-appium: true
run-ios: true
run-android: true
emulator-target: playstore
emulator-version: 30
# test-mobile-web:
# needs:
# - check-cloud
# uses: ./.github/workflows/_test-core-java.yml
# with:
# runs-on: macos-12
# suite-name: testng-mobile-web
# run-appium: true
# run-ios: true
# run-android: true
# emulator-target: playstore
# emulator-version: 30

test-mobile-bs:
needs:
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
- test-web-lt
- test-web-grid
- test-mobile-local
- test-mobile-web
# - test-mobile-web
- test-mobile-bs
- test-mobile-lt

Expand Down Expand Up @@ -216,11 +216,11 @@ jobs:
name: reports-testng-mobile-local
path: ${{ github.workspace }}/core-java/reports

- name: Download reports-testng-mobile-web files
uses: actions/download-artifact@v3
with:
name: reports-testng-mobile-web
path: ${{ github.workspace }}/core-java/reports
# - name: Download reports-testng-mobile-web files
# uses: actions/download-artifact@v3
# with:
# name: reports-testng-mobile-web
# path: ${{ github.workspace }}/core-java/reports

- name: Download reports-testng-mobile-lt files
uses: actions/download-artifact@v3
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<a href="https://mvnrepository.com/artifact/com.github.wasiqb.boyka/boyka-framework">
<img src="https://img.shields.io/maven-central/v/com.github.wasiqb.boyka/boyka-framework.svg?style=for-the-badge" alt="Maven Central" />
</a>
<a href="https://github.com/BoykaFramework/boyka-framework/releases/tag/v0.18.0">
<img src="https://img.shields.io/github/downloads/BoykaFramework/boyka-framework/v0.18.0/total?color=brightgreen&label=Downloads%20for%20v0.18.0&logo=GitHub&style=for-the-badge" alt="GitHub releases" />
<a href="https://github.com/BoykaFramework/boyka-framework/releases/tag/v0.19.0">
<img src="https://img.shields.io/github/downloads/BoykaFramework/boyka-framework/v0.19.0/total?color=brightgreen&label=Downloads%20for%20v0.19.0&logo=GitHub&style=for-the-badge" alt="GitHub releases" />
</a>
<a href="https://github.com/BoykaFramework/boyka-framework/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/BoykaFramework/boyka-framework.svg?style=for-the-badge" alt="license" />
Expand Down Expand Up @@ -90,7 +90,7 @@ Use this space to tell a little more about your project and how it can be used.
<dependency>
<groupId>com.github.wasiqb.boyka</groupId>
<artifactId>boyka-framework</artifactId>
<version>0.18.0</version>
<version>0.19.0</version>
</dependency>
```

Expand Down
13 changes: 13 additions & 0 deletions core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<codestyle.version>1.1.0</codestyle.version>
<checkstyle.version>10.12.5</checkstyle.version>
<aspectj.version>1.9.20.1</aspectj.version>
<poi.version>5.2.4</poi.version>
<suite-name>testng</suite-name>
<suite-xml>test-suites/${suite-name}.xml</suite-xml>
<argLine>-Dfile.encoding=UTF-8 -Xdebug -Xnoagent</argLine>
Expand Down Expand Up @@ -258,6 +259,18 @@
<artifactId>json-schema-validator</artifactId>
<version>${json-schema-validator.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* MIT License
*
* Copyright (c) 2023, Wasiq Bhamla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package com.github.wasiqb.boyka.actions.data;

import static com.github.wasiqb.boyka.utils.Validator.checkIndex;
import static java.util.Arrays.stream;

import java.util.Objects;

import com.github.wasiqb.boyka.actions.interfaces.data.IDataRow;

/**
* Gets test data in data row.
*
* @author Wasiq Bhamla
* @since 28-Nov-2023
*/
class DataRow implements IDataRow {
private final Object[] headers;
private final Object[] rowData;

DataRow (final Object[] headers, final Object[] rowData) {
this.headers = headers;
this.rowData = rowData;
}

@SuppressWarnings ("unchecked")
@Override
public <T> T cell (final int index) {
checkIndex (index, this.rowData.length);
return (T) this.rowData[index];
}

@Override
public <T> T cell (final String name) {
var colIndex = 0;
for (var index = 0; index < this.headers.length; index++) {
if (this.headers[index].equals (name)) {
colIndex = index;
break;
}
}
return cell (colIndex);
}

@Override
public boolean isEmpty () {
return stream (this.rowData).allMatch (Objects::isNull);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* MIT License
*
* Copyright (c) 2023, Wasiq Bhamla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package com.github.wasiqb.boyka.actions.data;

import static com.github.wasiqb.boyka.enums.ListenerType.TEST_DATA_ACTION;
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;
import static com.github.wasiqb.boyka.parser.DataFactory.getParser;
import static com.github.wasiqb.boyka.utils.Validator.checkIndex;
import static java.util.Objects.isNull;
import static java.util.Optional.ofNullable;
import static org.apache.logging.log4j.LogManager.getLogger;

import java.util.List;

import com.github.wasiqb.boyka.actions.interfaces.data.IDataRow;
import com.github.wasiqb.boyka.actions.interfaces.data.ITestDataAction;
import com.github.wasiqb.boyka.actions.interfaces.listeners.data.ITestDataActionsListener;
import com.github.wasiqb.boyka.parser.IDataParser;
import org.apache.logging.log4j.Logger;

/**
* Handle test data from different data source.
*
* @author Wasiq Bhamla
* @since 19-Nov-2023
*/
public class TestDataAction implements ITestDataAction {
private static final Logger LOGGER = getLogger ();

/**
* Handle test data.
*
* @param fileName Test data file name.
*
* @return {@link ITestDataAction} instance.
*/
public static ITestDataAction withData (final String fileName) {
return new TestDataAction (fileName);
}

private String blockName;
private List<Object[]> dataRow;
private final String fileName;
private Object[] headers;
private final ITestDataActionsListener listener;
private final IDataParser parser;

private TestDataAction (final String fileName) {
this.fileName = fileName;
this.listener = getSession ().getListener (TEST_DATA_ACTION);
this.parser = getParser ();
}

@Override
public <T> List<T> get (final Class<T> dataClass) {
LOGGER.info ("Getting list of Test data object...");
ofNullable (this.listener).ifPresent (d -> d.onGet (dataClass));
return this.parser.parse (this.fileName, this.blockName, dataClass);
}

@Override
public ITestDataAction inBlock (final String blockName) {
this.blockName = blockName;
return this;
}

@Override
public IDataRow row (final int index) {
LOGGER.info ("Getting Test data row at [{}] index...", index);
ofNullable (this.listener).ifPresent (d -> d.onRow (index));
final var rows = rows ();
checkIndex (index, rows.size ());
return rows.get (index);
}

@Override
public List<IDataRow> rows () {
LOGGER.info ("Getting all Test data rows...");
ofNullable (this.listener).ifPresent (ITestDataActionsListener::onRows);
if (isNull (this.dataRow) || this.dataRow.isEmpty ()) {
this.dataRow = this.parser.parse (this.fileName, this.blockName);
this.headers = this.dataRow.remove (0);
}
return this.dataRow.stream ()
.map (d -> (IDataRow) new DataRow (this.headers, d))
.filter (d -> !d.isEmpty ())
.toList ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void startRecording () {
final var setting = mobileSetting.getVideo ();
if (mobileSetting.getType () != CLOUD && setting.isEnabled ()) {
final var screen = (CanRecordScreen) getSession ().getDriver ();
ofNullable (this.listener).ifPresent (IDeviceActionsListener::onStartRecording);
startRecording (screen, setting, platform);
}
}
Expand All @@ -111,6 +112,7 @@ public void stopRecording () {
final var setting = mobileSetting.getVideo ();
if (mobileSetting.getType () != CLOUD && setting.isEnabled ()) {
final var screen = (CanRecordScreen) getSession ().getDriver ();
ofNullable (this.listener).ifPresent (IDeviceActionsListener::onStopRecording);
final var content = stopRecording (screen, platform);
saveVideo (content);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* MIT License
*
* Copyright (c) 2023, Wasiq Bhamla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package com.github.wasiqb.boyka.actions.interfaces.data;

/**
* Parses data row from data source.
*
* @author Wasiq Bhamla
* @since 19-Nov-2023
*/
public interface IDataRow {
/**
* Get cell data.
*
* @param index 1 based index of the cell.
*
* @return cell data.
*/
<T> T cell (int index);

/**
* Get cell data.
*
* @param name Cell name.
*
* @return cell data.
*/
<T> T cell (String name);

/**
* Checks if the row is empty.
*
* @return true, if row has all cells empty.
*/
boolean isEmpty ();
}
Loading

0 comments on commit 23e3624

Please sign in to comment.