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

fix(java): 🐛 session creation not req for test data #700

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
uses: ./.github/workflows/_test-core-java.yml
with:
suite-name: testng-others
runs-on: windows-latest

test-web-local:
needs:
Expand Down
2 changes: 1 addition & 1 deletion core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<checkstyle.version>10.12.5</checkstyle.version>
<aspectj.version>1.9.20.1</aspectj.version>
<poi.version>5.2.5</poi.version>
<suite-name>testng</suite-name>
<suite-name>testng-api</suite-name>
<suite-xml>test-suites/${suite-name}.xml</suite-xml>
<argLine>-Dfile.encoding=UTF-8 -Xdebug -Xnoagent</argLine>
<allureArgs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ public enum Message {
* Session already created.
*/
SESSION_ALREADY_CREATED ("Session is already created for ({0}) persona..."),
/**
* Session has not been created.
*/
SESSION_NOT_CREATED ("Session has not been created..."),
/**
* Error when starting session.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.github.wasiqb.boyka.actions.interfaces.listeners.BoykaListener;
import com.github.wasiqb.boyka.config.FrameworkSetting;
import com.github.wasiqb.boyka.config.TestDataSetting;
import com.github.wasiqb.boyka.config.api.ApiSetting;
import com.github.wasiqb.boyka.config.ui.mobile.MobileSetting;
import com.github.wasiqb.boyka.config.ui.web.WebSetting;
Expand Down Expand Up @@ -160,6 +161,15 @@ public <T> T getSharedData (final String key) {
return (T) this.sharedData.get (key);
}

/**
* Gets the test data settings.
*
* @return Test data setting.
*/
public TestDataSetting getTestDataSetting () {
return this.setting.getData ();
}

/**
* Gets current Web settings
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.github.wasiqb.boyka.enums.Message.SESSION_ALREADY_CLEARED;
import static com.github.wasiqb.boyka.enums.Message.SESSION_ALREADY_CREATED;
import static com.github.wasiqb.boyka.enums.Message.SESSION_NOT_CREATED;
import static com.github.wasiqb.boyka.enums.Message.SESSION_PERSONA_CANNOT_BE_NULL;
import static com.github.wasiqb.boyka.enums.PlatformType.API;
import static com.github.wasiqb.boyka.enums.PlatformType.WEB;
Expand Down Expand Up @@ -96,10 +95,10 @@ public static void clearSession () {
public static synchronized void createSession (final String persona, final PlatformType platformType,
final String configKey) {
switchPersona (persona);
final var currentSession = new DriverSession<> ();
checkSession ();
final var currentSession = getSession ();
currentSession.setPlatformType (platformType);
currentSession.setConfigKey (configKey);
setSession (currentSession);
if (platformType != API) {
final var instance = new DriverManager ();
instance.setupDriver ();
Expand Down Expand Up @@ -137,7 +136,7 @@ public static synchronized <D extends WebDriver> DriverSession<D> getSession ()
LOGGER.traceEntry ();
final var currentPersona = getCurrentPersona ();
if (!isSessionCreated ()) {
throwError (SESSION_NOT_CREATED);
setSession (new DriverSession<> ());
}
return LOGGER.traceExit ((DriverSession<D>) SESSION.get ()
.get (currentPersona));
Expand Down Expand Up @@ -181,14 +180,16 @@ static <D extends WebDriver> void setDriver (final D driver) {
LOGGER.traceExit ();
}

private static void checkSession () {
if (isSessionCreated ()) {
throwError (SESSION_ALREADY_CREATED, getCurrentPersona ());
}
}

private static synchronized <D extends WebDriver> void setSession (final DriverSession<D> session) {
final var persona = getCurrentPersona ();
final var currentSession = SESSION.get ();
if (!isSessionCreated ()) {
currentSession.put (persona, session);
} else {
throwError (SESSION_ALREADY_CREATED, persona);
}
currentSession.put (persona, session);
}

private ParallelSession () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public <T> List<T> parse (final String fileName, final String blockName, final C

@Override
public List<Object[]> parse (final String fileName, final String blockName) {
final var setting = getSession ().getSetting ()
.getData ();
final var setting = getSession ().getTestDataSetting ();
var filePath = Path.of (getProperty ("user.dir"), "src/test/resources", setting.getPath ())
.toAbsolutePath ();
if (setting.isExternal ()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class DataDrivenBookingTest {
@DataProvider
public Iterator<Object[]> getBookingData () {
public static Iterator<Object[]> getBookingData () {
final var rows = withData ("BookingData").inBlock ("Bookings")
.rows ();
return rows.stream ()
Expand All @@ -53,7 +53,7 @@ public Iterator<Object[]> getBookingData () {
}

@DataProvider
public Iterator<Object[]> getBookingDataObject () {
public static Iterator<Object[]> getBookingDataObject () {
final var rows = withData ("BookingData").inBlock ("Bookings")
.get (BookingTestData.class);
return rows.stream ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import static com.github.wasiqb.boyka.manager.ParallelSession.clearAllSessions;
import static com.github.wasiqb.boyka.manager.ParallelSession.clearSession;
import static com.github.wasiqb.boyka.manager.ParallelSession.createSession;
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;

import com.github.wasiqb.boyka.exception.FrameworkError;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

/**
Expand Down Expand Up @@ -57,22 +55,13 @@ public void testDuplicateClearSession () {
/**
* Test Duplicate Session creation.
*/
@Ignore
@Test (description = "Test Duplicate Session creation", expectedExceptions = FrameworkError.class, expectedExceptionsMessageRegExp = "Session is already created for .SessionTest. persona...")
public void testDuplicateSessionCreation () {
createSession (PERSONA, WEB, "test_local_chrome");
createSession (PERSONA, WEB, "test_local_chrome");
clearSession ();
}

/**
* Test get session without session creation.
*/
@Test (description = "Test get session without session creation", expectedExceptions = FrameworkError.class, expectedExceptionsMessageRegExp = "Session has not been created...")
public void testGetSessionWithoutSessionCreated () {
getSession ();
}

/**
* Test session creation with Null persona.
*/
Expand Down