Skip to content

Conversation

ismail-elshafeiy
Copy link
Owner

@ismail-elshafeiy ismail-elshafeiy commented Nov 23, 2024

PR Type

Enhancement, Tests, Configuration changes, Documentation, Error handling, Test data, Miscellaneous


Description

  • Introduced several utility classes (Clocks, Resources, StringHelper, Lists) for enhanced operations on date-time, file handling, string manipulation, and list operations.
  • Added LoggerFactory and related classes for structured logging and custom log formatting.
  • Refactored multiple classes (RestApiActions, GraphQlActions, ScreenShot, etc.) for immutability and code simplification.
  • Added test cases for Clocks and SOAP API endpoints using RestAssured.
  • Introduced Config and ConfigFactory classes for application configuration management.
  • Added extensive test data files (JSON, XML, text) for various testing scenarios.
  • Updated pom.xml files to include new modules and plugin configurations.
  • Added documentation files for test result visualization using Extent Reports.
  • Introduced custom exceptions (DataStreamException, DataTableException) for error handling in stream and table operations.
  • Added annotations (DataFile, Lifecycle) for configuration and lifecycle management.

Changes walkthrough 📝

Relevant files
Enhancement
26 files
Clocks.java
Introduce `Clocks` utility class for date-time operations

collections/src/main/java/com/collections/Clocks.java

  • Added a utility class Clocks for date and time operations.
  • Introduced methods for parsing, formatting, and adjusting dates and
    times.
  • Implemented error handling for date parsing exceptions.
  • Defined constants for date and time formats.
  • +338/-0 
    Resources.java
    Add `Resources` utility class for file handling                   

    collections/src/main/java/com/collections/Resources.java

  • Added Resources utility class for file operations.
  • Implemented methods for file path resolution and file stream handling.
  • Introduced error handling with DataStreamException.
  • Provided methods for copying and writing to files.
  • +273/-0 
    StringHelper.java
    Add `StringHelper` utility class for string operations     

    collections/src/main/java/com/collections/StringHelper.java

  • Added StringHelper utility class for string manipulation.
  • Implemented methods for case conversion and pattern matching.
  • Introduced string interpolation and version extraction methods.
  • Provided utility methods for checking string emptiness.
  • +188/-0 
    LoggerFactory.java
    Introduce `LoggerFactory` for logging management                 

    commons/src/main/java/com/commons/logging/LoggerFactory.java

  • Added LoggerFactory class for creating loggers.
  • Implemented listener pattern for log record handling.
  • Introduced DelegatingLogger for logging with different levels.
  • Provided methods for adding and removing log listeners.
  • +171/-0 
    Lists.java
    Add `Lists` utility class for list manipulations                 

    collections/src/main/java/com/collections/Lists.java

  • Added Lists utility class for list operations.
  • Implemented methods for creating and filtering lists.
  • Introduced case-insensitive list functionality.
  • Provided methods for sorting and converting lists to strings.
  • +136/-0 
    Logger.java
    Define `Logger` interface for structured logging                 

    commons/src/main/java/com/commons/logging/Logger.java

  • Added Logger interface for logging operations.
  • Defined methods for logging at various levels (error, warn, info,
    etc.).
  • Mapped logging methods to corresponding Java logging levels.
  • +123/-0 
    RestApiActions.java
    Refactor `RestApiActions` for immutability and code simplification

    src/main/java/com/engine/actions/RestApiActions.java

  • Made sessionFilter, cookieFilter, and baseUrl fields final.
  • Simplified return statements in JSON value retrieval methods.
  • Adjusted access modifiers for RequestType enum methods.
  • +9/-17   
    SelcukesLoggerFormatter.java
    Add `SelcukesLoggerFormatter` for custom log formatting   

    commons/src/main/java/com/commons/logging/SelcukesLoggerFormatter.java

  • Added SelcukesLoggerFormatter class for custom log formatting.
  • Implemented method to format log records with class and method
    details.
  • Mapped log levels to custom string representations.
  • +61/-0   
    Helper.java
    Refactor `Helper` class for charset consistency and code clarity

    src/main/java/com/engine/Helper.java

  • Replaced Charset.forName("UTF-8") with StandardCharsets.UTF_8.
  • Simplified string operations in getDate and getAlphaNumericString.
  • Improved loop iteration in removeSpecialCharacters.
  • +4/-3     
    SelcukesColorFormatter.java
    Add `SelcukesColorFormatter` for colored logging output   

    commons/src/main/java/com/commons/logging/SelcukesColorFormatter.java

  • Added SelcukesColorFormatter class for colored log output.
  • Implemented method to apply color codes based on log level.
  • Extended SelcukesLoggerFormatter for base formatting.
  • +45/-0   
    ElementHelper.java
    Refactor `ElementHelper` for improved logging and timeout handling

    src/main/java/com/engine/actions/helper/ElementHelper.java

  • Simplified error logging in identifyUniqueElement.
  • Adjusted timeout calculation in waitForElementPresence.
  • +2/-2     
    EyesManager.java
    Refactor EyesManager for charset consistency and logic simplification

    src/main/java/com/engine/validations/EyesManager.java

  • Replaced charset string with StandardCharsets.UTF_8.
  • Simplified PDF validation logic.
  • Adjusted static field assignments in constructor.
  • +6/-9     
    LogRecordListener.java
    Add `LogRecordListener` for log record management               

    commons/src/main/java/com/commons/logging/LogRecordListener.java

  • Added LogRecordListener class for handling log records.
  • Implemented methods to retrieve and filter log records by level.
  • Provided cleanup method for thread-local storage.
  • +45/-0   
    GraphQlActions.java
    Refactor `GraphQlActions` for immutability and access control

    src/main/java/com/engine/actions/GraphQlActions.java

  • Made jsonObject and requestSpec fields final.
  • Adjusted access modifier for StatusCode enum method.
  • +4/-4     
    ScreenShot.java
    Refactor `ScreenShot` for immutability and thread-local usage

    src/main/java/com/engine/evidence/ScreenShot.java

  • Made gifRelativePathWithFileName field final.
  • Adjusted thread-local variables for GIF output stream and writer.
  • +3/-3     
    ScreenshotManager.java
    Refactor `ScreenshotManager` for immutability and thread-local usage

    src/main/java/com/engine/evidence/ScreenshotManager.java

  • Made gifOptions and gifDelay fields final.
  • Adjusted thread-local variables for GIF output stream and writer.
  • +2/-2     
    DataProvider.java
    Refactor `DataProvider` for static method usage                   

    src/main/java/com/engine/dataDriven/DataProvider.java

  • Updated method calls to use ExcelFileManager statically.
  • Adjusted data retrieval logic in getExcelData.
  • +3/-3     
    EmailAttachmentsSender.java
    Simplify `EmailAttachmentsSender` and remove unused exception

    src/main/java/com/engine/mail/EmailAttachmentsSender.java

  • Removed unused exception from method signature.
  • Simplified attachment handling logic.
  • +2/-2     
    BrowserActions.java
    Simplify logging in `BrowserActions` frame switching         

    src/main/java/com/engine/actions/BrowserActions.java

    • Simplified logging statement in switchToFrame.
    +1/-1     
    JSONFileManager.java
    Simplify `JSONFileManager` initialization and enum constructor

    src/main/java/com/engine/dataDriven/JSONFileManager.java

  • Removed redundant initialization of reader.
  • Simplified constructor of DataType enum.
  • +2/-2     
    DecodeData.java
    Refactor `DecodeData` for immutability                                     

    src/main/java/com/engine/utils/DecodeData.java

    • Made encryptionKeyString field final.
    +1/-1     
    DataFile.java
    Add `DataFile` annotation for data file configuration       

    commons/src/main/java/com/commons/annotation/DataFile.java

  • Added DataFile annotation for data file configuration.
  • Defined attributes for file name, folder path, and stream loading.
  • +20/-0   
    CustomReporter.java
    Refactor `CustomReporter` for immutability                             

    src/main/java/com/engine/reports/CustomReporter.java

    • Made currentTime field final.
    +1/-1     
    Lifecycle.java
    Add `Lifecycle` annotation for lifecycle management           

    commons/src/main/java/com/commons/annotation/Lifecycle.java

  • Added Lifecycle annotation for lifecycle management.
  • Defined Type enum for specifying lifecycle scope.
  • +19/-0   
    TerminalActions.java
    Refactor `TerminalActions` for immutability                           

    src/main/java/com/engine/actions/TerminalActions.java

    • Made dockerName field final.
    +1/-1     
    ElementActions.java
    Refactor `ElementActions` for static field assignment       

    src/main/java/com/engine/actions/ElementActions.java

    • Adjusted static field assignment in constructor.
    +1/-1     
    Tests
    2 files
    ClocksTest.java
    Add test cases for `Clocks` utility class                               

    collections/src/test/java/ClocksTest.java

  • Added test class ClocksTest for testing Clocks utility methods.
  • Implemented test cases for date and time parsing and formatting.
  • Verified date-time adjustments and differences.
  • Included tests for timezone-specific date-time operations.
  • +162/-0 
    SoapTest.java
    Add SOAP API test cases using RestAssured                               

    src/test/java/api/soap/SoapTest.java

  • Added SoapTest class for testing SOAP API endpoints.
  • Implemented test cases for ISBN validation and language listing.
  • Utilized RestAssured for sending SOAP requests.
  • Verified response status and extracted XML data.
  • +86/-0   
    Configuration changes
    7 files
    Config.java
    Introduce `Config` class for application configuration     

    commons/src/main/java/com/commons/config/Config.java

  • Added Config class with nested configuration classes.
  • Annotated with @DataFile for YAML configuration loading.
  • Defined configuration fields for project, web, mobile, and
    notifications.
  • +84/-0   
    ConfigFactory.java
    Add `ConfigFactory` for configuration management                 

    commons/src/main/java/com/commons/config/ConfigFactory.java

  • Added ConfigFactory class for managing configuration instances.
  • Implemented singleton pattern for Config retrieval.
  • Provided method to load logger properties from a YAML file.
  • +52/-0   
    pom.xml
    Update `pom.xml` for module inclusion and plugin update   

    pom.xml

  • Added modules for collections and commons.
  • Updated Maven Jar Plugin version and configuration.
  • +13/-20 
    selcukes.yaml
    Add YAML configuration for Selcukes environment                   

    commons/src/test/resources/selcukes.yaml

  • Added a YAML configuration file for Selcukes environment properties.
  • Includes settings for project, web, mobile, and reports.
  • +49/-0   
    pom.xml
    Add Maven POM file for collections module                               

    collections/pom.xml

  • Added a Maven POM file for the collections module.
  • Specifies project details and compiler properties.
  • +20/-0   
    pom.xml
    Add Maven POM file for commons module                                       

    commons/pom.xml

  • Added a Maven POM file for the commons module.
  • Specifies project details and compiler properties.
  • +20/-0   
    org.testng.ITestNGListener
    Add TestNG listener configuration file                                     

    src/test/resources/META-INF.services/org.testng.ITestNGListener

  • Added a service file for TestNG listener configuration.
  • Specifies com.engine.listeners.TestNGListener as the listener.
  • +1/-0     
    Error handling
    2 files
    DataStreamException.java
    Introduce `DataStreamException` for stream error handling

    collections/src/main/java/com/collections/exception/DataStreamException.java

  • Added DataStreamException class for stream-related errors.
  • Provided constructors for various exception scenarios.
  • +23/-0   
    DataTableException.java
    Introduce `DataTableException` for table error handling   

    collections/src/main/java/com/collections/exception/DataTableException.java

  • Added DataTableException class for table-related errors.
  • Provided constructors for various exception scenarios.
  • +23/-0   
    Miscellaneous
    1 files
    GMailer.java
    Adjust `GMailer` main method for mail sending                       

    src/main/java/com/engine/mail/GMailer.java

    • Adjusted method call in main for sendMail.
    +2/-1     
    Documentation
    1 files
    ExtentReports.html
    Add Extent Report HTML for test result visualization         

    ExtentReport/ExtentReports.html

  • Added HTML file for Extent Report visualization.
  • Included structure for displaying test results and logs.
  • +386/-0 
    Dependencies
    3 files
    photosforalbum.json
    Add JSON data file for album photos                                           

    src/test/resources/newFolder/__files/photosforalbum.json

  • Added JSON file with photo data for album.
  • Included fields for album ID, title, and URLs.
  • +352/-0 
    users.json
    Add JSON data file for user information                                   

    src/test/resources/newFolder/__files/users.json

  • Added JSON file with user data.
  • Included fields for user details and contact information.
  • +232/-0 
    CarDeserialization.json
    Add JSON mapping file for car deserialization                       

    src/test/resources/newFolder/mappings/CarDeserialization.json

  • Added JSON mapping file for car deserialization.
  • Defined request and response structure for car data.
  • +11/-0   
    Test data
    25 files
    albums.json
    Add JSON file with album data for testing                               

    src/test/resources/newFolder/__files/albums.json

  • Added a JSON file containing a list of albums with user IDs and
    titles.
  • The file includes 100 album entries.
  • +502/-0 
    jsonFile.json
    Add JSON file with user data for testing                                 

    src/test/resources/newFolder/mappings/jsonFile.json

  • Added a JSON file with user data including IDs, names, emails, and
    genders.
  • Contains 10 user entries.
  • +62/-0   
    24848.xml
    Add XML file with German location data                                     

    src/test/resources/newFolder/__files/24848.xml

  • Added an XML file with location data for postcode 24848 in Germany.
  • Includes details about places within the postcode.
  • +28/-0   
    DE24848.json
    Add JSON mapping for German postcode 24848                             

    src/test/resources/newFolder/mappings/DE24848.json

  • Added a JSON mapping file for a GET request to /de/24848.
  • Provides a JSON response with location data for postcode 24848 in
    Germany.
  • +12/-0   
    cars.xml
    Add XML file with car data for testing                                     

    src/test/resources/newFolder/__files/cars.xml

  • Added an XML file with car data including make, model, country, and
    model year.
  • Contains data for three cars.
  • +16/-0   
    90210.xml
    Add XML file with US location data for postcode 90210       

    src/test/resources/newFolder/__files/90210.xml

  • Added an XML file with location data for postcode 90210 in the United
    States.
  • Includes details about places within the postcode.
  • +13/-0   
    US12345.json
    Add JSON mapping for US postcode 12345                                     

    src/test/resources/newFolder/mappings/US12345.json

  • Added a JSON mapping file for a GET request to /us/12345.
  • Provides a JSON response with location data for postcode 12345 in the
    United States.
  • +11/-0   
    CAY1A.json
    Add JSON mapping for Canadian postcode Y1A                             

    src/test/resources/newFolder/mappings/CAY1A.json

  • Added a JSON mapping file for a GET request to /ca/Y1A.
  • Provides a JSON response with location data for postcode Y1A in
    Canada.
  • +11/-0   
    US90210.json
    Add JSON mapping for US postcode 90210                                     

    src/test/resources/newFolder/mappings/US90210.json

  • Added a JSON mapping file for a GET request to /us/90210.
  • Provides a JSON response with location data for postcode 90210 in the
    United States.
  • +11/-0   
    CarSerialization.json
    Add JSON mapping for car serialization endpoint                   

    src/test/resources/newFolder/mappings/CarSerialization.json

  • Added a JSON mapping file for a POST request to /car/postcar.
  • Provides a JSON response indicating success for car serialization.
  • +14/-0   
    AddressDeserialization.json
    Add JSON mapping for address deserialization endpoint       

    src/test/resources/newFolder/mappings/AddressDeserialization.json

  • Added a JSON mapping file for a GET request to /address.
  • Provides a JSON response with address data for deserialization.
  • +11/-0   
    US99999.json
    Add JSON mapping for non-existent US postcode 99999           

    src/test/resources/newFolder/mappings/US99999.json

  • Added a JSON mapping file for a GET request to /us/99999.
  • Provides a JSON response with an error message for non-existent US
    postcode.
  • +11/-0   
    DE24848Xml.json
    Add JSON mapping for German postcode 24848 with XML response

    src/test/resources/newFolder/mappings/DE24848Xml.json

  • Added a JSON mapping file for a GET request to /xml/de/24848.
  • Provides an XML response with location data for postcode 24848 in
    Germany.
  • +11/-0   
    TestData.txt
    Add text file with authentication test data                           

    src/test/resources/TestData/text/TestData.txt

  • Added a text file with repeated username and password entries.
  • Contains test data for authentication scenarios.
  • +32/-0   
    PhotosForAlbum.json
    Add JSON mapping for photos of album 35                                   

    src/test/resources/newFolder/mappings/PhotosForAlbum.json

  • Added a JSON mapping file for a GET request to /albums/35/photos.
  • Provides a JSON response with a file reference for photos related to
    album 35.
  • +11/-0   
    TestData.txt
    Add text file with authentication test data                           

    src/test/resources/newFolder/text/TestData.txt

  • Added a text file with repeated username and password entries.
  • Contains test data for authentication scenarios.
  • +32/-0   
    24848_xml.json
    Add JSON mapping for German postcode 24848 with XML response

    src/test/resources/newFolder/mappings/24848_xml.json

  • Added a JSON mapping file for a GET request to /de/24848.
  • Provides an XML response with location data for postcode 24848 in
    Germany.
  • +11/-0   
    90210_xml.json
    Add JSON mapping for US postcode 90210 with XML response 

    src/test/resources/newFolder/mappings/90210_xml.json

  • Added a JSON mapping file for a GET request to /us/90210.
  • Provides an XML response with location data for postcode 90210 in the
    United States.
  • +11/-0   
    AddressSerialization.json
    Add JSON mapping for address serialization endpoint           

    src/test/resources/newFolder/mappings/AddressSerialization.json

  • Added a JSON mapping file for a POST request to /address.
  • Provides a JSON response indicating success for address serialization.

  • +11/-0   
    CarsXml.json
    Add JSON mapping for cars XML endpoint                                     

    src/test/resources/newFolder/mappings/CarsXml.json

  • Added a JSON mapping file for a GET request to /xml/cars.
  • Provides an XML response with car data.
  • +11/-0   
    AlbumsJson.json
    Add JSON mapping for albums JSON endpoint                               

    src/test/resources/newFolder/mappings/AlbumsJson.json

  • Added a JSON mapping file for a GET request to /albums.
  • Provides a JSON response with a file reference for album data.
  • +11/-0   
    UsersJson.json
    Add JSON mapping for users JSON endpoint                                 

    src/test/resources/newFolder/mappings/UsersJson.json

  • Added a JSON mapping file for a GET request to /users.
  • Provides a JSON response with a file reference for user data.
  • +11/-0   
    TestData.json
    Add JSON file with authentication test data                           

    src/test/resources/newFolder/json/TestData.json

  • Added a JSON file with test data for user authentication.
  • Includes email, password, and expected success message.
  • +13/-0   
    location.json
    Add JSON mapping for location endpoint                                     

    src/test/resources/newFolder/mappings/location.json

  • Added a JSON mapping file for a POST request to /lv/1050.
  • Provides a response status of 200.
  • +9/-0     
    TestData.json
    Add JSON file with API authentication test data                   

    src/test/resources/newFolder/ApisData/TestData.json

  • Added a JSON file with test data for API authentication.
  • Includes email, password, and expected success message.
  • +9/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @ismail-elshafeiy ismail-elshafeiy merged commit 053c7a8 into master Nov 23, 2024
    0 of 3 checks passed
    @ismail-elshafeiy ismail-elshafeiy deleted the testing2 branch November 23, 2024 12:20
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 PR contains tests
    🔒 Security concerns

    Sensitive information exposure:
    The LoggerFactory class logs stack traces and method names which could expose internal implementation details that may be useful for attackers. Consider limiting the logged information in production environments.

    ⚡ Recommended focus areas for review

    Possible Bug
    The toString() method in Lists class assumes the input object is non-null, which could cause NullPointerException if a null object is passed

    Performance Issue
    The dateTimeFormatter() method creates a new DateTimeFormatter instance on each call, which is inefficient. Consider caching common formatters

    Code Smell
    The DelegatingLogger class has complex nested if conditions and duplicated code in log methods. Consider refactoring to reduce complexity

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Fixed empty loop that was not populating the data array with values from Excel

    The data array is being populated incorrectly - the loop iterates but no data is
    being assigned. Move the data assignments inside the loop to properly populate the
    array.

    src/main/java/com/engine/dataDriven/DataProvider.java [14]

     for (int row = 0; row < numberOfRows; row++) {
    +    data[row][0] = ExcelFileManager.getCellData(row + 1, "email");
    +    data[row][1] = ExcelFileManager.getCellData(row + 1, "password"); 
    +    data[row][2] = ExcelFileManager.getCellData(row + 1, "expectedResult_successMessage");
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Critical bug fix - the current code has an empty loop that fails to populate the data array, making the DataProvider non-functional. The fix properly assigns Excel data to the array.

    9
    Add null parameter validation to prevent runtime exceptions

    Add null check for the temporal parameter in the adjust() method to prevent
    NullPointerException when passing null temporal object.

    collections/src/main/java/com/collections/Clocks.java [244-248]

    -public <T extends Temporal> T adjust(T temporal, @NonNull String name) {
    +public <T extends Temporal> T adjust(@NonNull T temporal, @NonNull String name) {
         return ofNullable(ADJUSTERS.get(name))
                 .map(temporal::with)
                 .map(t -> (T) t)
                 .orElseThrow(() -> new IllegalArgumentException("Unknown adjustment: " + name));
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding @nonnull validation for the temporal parameter is crucial for preventing NullPointerException at runtime, which could crash the application. This is a significant improvement for method robustness.

    8
    Add null check to prevent runtime exceptions

    Add null check in nonEmpty() method to prevent NullPointerException when value
    parameter is null.

    collections/src/main/java/com/collections/Lists.java [57-65]

     public <T> boolean nonEmpty(T value) {
    +    if (value == null) {
    +        return false;
    +    }
         if (value instanceof Collection<?> collection) {
             return !collection.isEmpty();
         }
         if (value instanceof Object[] objects) {
             return objects.length > 0;
         }
         return StringHelper.isNonEmpty(value.toString());
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a null check in the nonEmpty() method is essential to prevent NullPointerException. Since this is a utility method likely to be used frequently, preventing runtime crashes is critical for application stability.

    8
    Fixed incorrect assertion of XML response by properly extracting and comparing the boolean value

    The assertion is comparing a complex XML response directly with "true" which will
    fail. Extract the specific boolean value from the XML response before assertion.

    src/test/java/api/soap/SoapTest.java [44]

    -Assert.assertEquals(isValidISBN13Result, "true");
    +boolean isValid = Boolean.parseBoolean(xmlPath.getString("soap:Envelope.soap:Body.m:IsValidISBN13Response.m:IsValidISBN13Result"));
    +Assert.assertTrue(isValid);
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Important fix for a test assertion that would always fail due to comparing complex XML with a string "true". The improved code correctly extracts and validates the boolean value.

    8
    Fixed thread-safety issue by properly assigning driver instance variable instead of static field

    The constructor assigns to the static field using ElementActions.driver which hides
    the instance field. This creates thread-safety issues in concurrent execution.

    src/main/java/com/engine/actions/ElementActions.java [32]

     public ElementActions(WebDriver driver) {
    -    ElementActions.driver = driver;
    +    this.driver = driver;
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Addresses a significant thread-safety concern where static field assignment could cause issues in concurrent test execution.

    7

    💡 Need additional feedback ? start a PR chat

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant