{"id":17537231,"url":"https://github.com/jmsdaq/selenium-testng-cucumber","last_synced_at":"2026-04-20T09:32:42.152Z","repository":{"id":257865520,"uuid":"864475469","full_name":"jmsdaq/selenium-testng-cucumber","owner":"jmsdaq","description":"Automated BDD testing with Cucumber, Selenium, and TestNG using POM.","archived":false,"fork":false,"pushed_at":"2024-12-18T00:53:05.000Z","size":865,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T03:23:50.747Z","etag":null,"topics":["allure-report","cross-browser-testing","cucumber-java","dependency-injection-container","maven","maven-plugin","page-object-model","parallel-tests","pico-container","selenium-webdriver","testng","webdriver-manager"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmsdaq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-28T10:15:23.000Z","updated_at":"2024-12-18T00:53:09.000Z","dependencies_parsed_at":"2024-12-07T07:30:33.799Z","dependency_job_id":null,"html_url":"https://github.com/jmsdaq/selenium-testng-cucumber","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"84582e5d133d48a605a2a4f9cb063081666584f5"},"previous_names":["jmsdaq/selenium-testng-cucumber"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jmsdaq/selenium-testng-cucumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmsdaq%2Fselenium-testng-cucumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmsdaq%2Fselenium-testng-cucumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmsdaq%2Fselenium-testng-cucumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmsdaq%2Fselenium-testng-cucumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmsdaq","download_url":"https://codeload.github.com/jmsdaq/selenium-testng-cucumber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmsdaq%2Fselenium-testng-cucumber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32041350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["allure-report","cross-browser-testing","cucumber-java","dependency-injection-container","maven","maven-plugin","page-object-model","parallel-tests","pico-container","selenium-webdriver","testng","webdriver-manager"],"created_at":"2024-10-20T20:06:14.624Z","updated_at":"2026-04-20T09:32:42.109Z","avatar_url":"https://github.com/jmsdaq.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selenium TestNG Cucumber Project\n\n## Overview\nThis project uses Cucumber, Selenium, and TestNG, focusing on Behavior-Driven Development (BDD) and the Page Object Model (POM). Cucumber allows for plain language specifications, promoting collaboration, while POM enhances code organization. TestNG facilitates streamlined test execution and reporting, creating an efficient testing framework.\n\n## Supports\n- Page Object Model\n- Page Context (DI)\n- Headless Run\n- Data-Driven Testing (DDT)\n- Tagging Tests\n- Failed Screenshot\n- Chaining Methods\n- Parallel Test\n- Allure Report\n\n\n## Setups\n- Install **Selenium WebDriver**.   \n- Configure **TestNG** in `testng.xml`.\n- Write feature files in **Cucumber**.\n- Implement **Page Object Model (POM)**.\n- Use **Hooks** for setup and teardown.\n\n## Prerequisites\n- Java JDK 8 or higher\n- Maven\n- IDE (IntelliJ IDEA, Eclipse)\n- WebDriver (e.g., ChromeDriver)\n\n## Page Object Model\nThe Page Object Model (POM) is implemented to create an object repository for web UI elements. Each page of the application is represented by a class, which contains methods that correspond to the actions that can be performed on that page.\n\nFor example, a login page class might look like this:\n```java\npublic class LoginPage {\n    private WebDriver driver;\n\n    @FindBy(id = \"username\") private WebElement usernameField;\n    @FindBy(id = \"password\") private WebElement passwordField;\n    @FindBy(id = \"loginButton\") private WebElement loginButton;\n\n    public LoginPage(WebDriver driver) {\n        this.driver = driver;\n        PageFactory.initElements(driver, this);\n    }\n\n    public LoginPage enterCredentials(String username, String password) {\n        usernameField.sendKeys(username);\n        passwordField.sendKeys(password);\n        return this;\n    }\n\n    public HomePage clickLogin() {\n        loginButton.click();\n        return new HomePage(driver);\n    }\n}\n\n// Usage\nnew LoginPage(driver)\n    .enterCredentials(\"user1\", \"pass1\")\n    .clickLogin();\n```\nIn this example, methods return the current instance, allowing for a smooth sequence of actions. POM enhances clarity and maintainability, making it easier to adapt to UI changes.\n\n## Tagging Tests\nCucumber allows for tagging tests to organize and run specific scenarios. Tags can be added in feature files and can be executed with the command line using:\n```\ncucumber --tags @tagName\n```\n\n## Headless Run\nThe headless mode is enabled by default for Chrome, Firefox, and Edge. You can control this via Maven properties.\n\nTo run the tests in headless mode, use the following Maven command:\n```bash\nmvn clean test -Dbrowser=chrome -Dheadless=true\n```\n- `Dbrowser=chrome`: Use Chrome as the browser (you can replace it with `firefox` or `edge`).\n- `Dheadless=true`: Enables headless mode.\n\n### Hooks.java\n```java\n// Inside Hooks.java\nChromeOptions options = new ChromeOptions();\nif (headless) {\n        options.addArguments(\"--headless\", \"--disable-gpu\", \"--window-size=1920,1080\");\n// Add additional configurations as needed\n}\n```\n\n### BrowserDriverFactory.java\n```java\n// Inside BrowserDriverFactory.java\nif (headless) {\n        chromeOptions.addArguments(\"--headless\");\n    firefoxOptions.addArguments(\"--headless\");\n    edgeOptions.addArguments(\"--headless\");\n}\n```\n### Explanation:\n- **Hooks.java**: The headless option is added for Chrome in the `Hooks` class if the `headless` flag is true. Additional options can be added as required.\n- **BrowserDriverFactory.java**: Similar configuration is applied for Chrome, Firefox, and Edge browsers in `BrowserDriverFactory` for cross-browser headless testing.\n\nThis ensures the tests run in headless mode across different browsers, providing a faster and more efficient execution in CI/CD pipelines.\n\n## Failed Screenshot\n\nCapture screenshots on test failure and attach them to Cucumber and Allure reports.\n\n### Code to Capture Screenshot on Failure\n\n```\npublic void afterScenario(Scenario scenario) {\n    if (scenario.isFailed()) {\n        byte[] screenshot = takeScreenshot();\n        scenario.attach(screenshot, \"image/png\", \"Screenshot on Failure\"); // Attach to Cucumber\n        saveScreenshotToAllure(screenshot); // Attach to Allure\n    }\n    context.getDriver().quit();\n}\n\nprivate byte[] takeScreenshot() {\n    return context.getDriver().getScreenshotAs(OutputType.BYTES);\n}\n\n@io.qameta.allure.Attachment(value = \"Screenshot on Failure\", type = \"image/png\")\nprivate byte[] saveScreenshotToAllure(byte[] screenshot) {\n    return screenshot; // Attach to Allure\n}\n```\n## Chaining method\nMethod chaining is a programming technique where multiple method calls are made in a single statement. This is particularly useful in POM as it can lead to more readable and concise code. In this project, methods in page classes can return `this`, allowing for easy chaining of actions.\n\nFor instance, in a login page class, methods can be designed to return the current instance of the class, allowing the next method to be called directly on the same object:\n```java\npublic class LoginPage {\n    public LoginPage enterUsername(String username) {\n        usernameField.sendKeys(username);\n        return this;\n    }\n\n    public LoginPage enterPassword(String password) {\n        passwordField.sendKeys(password);\n        return this;\n    }\n\n    public HomePage clickLogin() {\n        loginButton.click();\n        return new HomePage();\n    }\n}\n```\nUsing chaining in your test code makes it more fluent and easier to understand:\n```java\nLoginPage loginPage = new LoginPage(driver);\nloginPage.enterUsername(\"user1\")\n          .enterPassword(\"pass1\")\n          .clickLogin();\n```\nThis technique enhances code readability and reduces boilerplate code, making it easier to write and maintain tests.\n\n## Running Tests in Parallel with TestNG\nTestNG supports parallel test execution, making your tests run faster. You can set this up in the testng.xml file by specifying how you want the tests to run.\n\nExample: `testng.xml`\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003csuite name=\"Tests\" parallel=\"classes\" thread-count=\"3\"\u003e\n    \u003ctest name=\"ChromeTests\"\u003e\n        \u003cparameter name=\"browser\" value=\"chrome\"/\u003e\n        \u003cparameter name=\"headless\" value=\"true\"/\u003e\n        \u003cclasses\u003e\n            \u003cclass name=\"runner.LoginTestRunner\" /\u003e\n            \u003cclass name=\"runner.ProductTestRunner\" /\u003e\n        \u003c/classes\u003e\n    \u003c/test\u003e\n\u003c/suite\u003e\n```\nIn this configuration:\n\n- `parallel=\"methods\"` enables parallel execution of test methods within classes.\n- `thread-count=\"3\"` specifies that up to 3 threads can run simultaneously.\nThis setup allows for multiple tests to be executed concurrently, improving overall test execution time while maintaining test isolation.\n## Cross-Browser Testing\nCross-browser testing ensures your application performs consistently across different browsers. TestNG simplifies this by allowing browser-specific configurations in the `testng.xml` file.\n\nExample for multiple browsers:\n```\n    \u003ctest name=\"BrowserTests\"\u003e  \n        \u003cparameter name=\"browser\" value=\"chrome\"/\u003e  \n        \u003cclasses\u003e  \n            \u003cclass name=\"runner.LoginTestRunner\" /\u003e  \n        \u003c/classes\u003e  \n    \u003c/test\u003e  \n    \u003ctest name=\"BrowserTests\"\u003e  \n        \u003cparameter name=\"browser\" value=\"firefox\"/\u003e  \n        \u003cclasses\u003e  \n            \u003cclass name=\"runner.LoginTestRunner\" /\u003e  \n        \u003c/classes\u003e  \n    \u003c/test\u003e  \n```\nEach `\u003ctest\u003e` block specifies a browser, enabling automated testing across Chrome, Firefox, and Edge in a single run. This ensures browser compatibility while maintaining efficient test organization.\n### Clone the Repository\n```bash\ngit clone https://github.com/username/repository.git\ncd repository\n```\n\n## Installation\n1. Navigate to the project directory.\n\n2. Install project dependencies using Maven:\n```bash\nmvn clean install\n```\n3. Configure any required environment variables or settings in your `config.properties` file.\n\n## Allure Report\n#### Maven Configuration for Allure\nTo generate Allure reports after test execution, add the following plugin to your `pom.xml` file.\n```\n\u003cplugins\u003e\n    \u003c!-- Allure Maven Plugin --\u003e\n    \u003cplugin\u003e\n        \u003cgroupId\u003eio.qameta.allure\u003c/groupId\u003e\n        \u003cartifactId\u003eallure-maven\u003c/artifactId\u003e\n        \u003cversion\u003e2.15.2\u003c/version\u003e\n        \u003cexecutions\u003e\n            \u003cexecution\u003e\n                \u003cgoals\u003e\n                    \u003cgoal\u003eaggregate\u003c/goal\u003e\n                \u003c/goals\u003e\n            \u003c/execution\u003e\n        \u003c/executions\u003e\n    \u003c/plugin\u003e\n\u003c/plugins\u003e\n```\nNote: The correct goal to use for generating and aggregating Allure reports is `aggregate`, not `generate` or `serve`.\n###     Generating and Serving the Report\nAfter running tests, you can generate and view Allure reports to analyze results and failures. To generate the report:\n\n1. Run your tests using:\n```bash\nmvn test\n```\n2. Generate the Allure report:\n```bash\nmvn allure:report\n```\n3. Serve the report:\n```bash\nmvn allure:serve\n```\n### Example Screenshots\n![Allure Report](screenshots/ss1.png)\n\n![Allure Report](screenshots/ss2.png)\nThe reports will provide insights into passed, failed, and skipped tests along with detailed information on each test case. Screenshots of failed tests are included to provide visual context, enhancing the debugging process.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmsdaq%2Fselenium-testng-cucumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmsdaq%2Fselenium-testng-cucumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmsdaq%2Fselenium-testng-cucumber/lists"}