1.0.134 • Published 10 days ago

luopaieasyjs v1.0.134

Weekly downloads
-
License
ISC
Repository
github
Last release
10 days ago

SelenaJS

SelenaJS is a lightweight testing framework for Node.js, designed to simplify the creation and execution of end-to-end tests. With SelenaJS, you can easily define and organize your tests, and execute them in a reliable and repeatable way.

Installation

To use SelenaJS, you need to install it through npm. Open a terminal window and type:

npm install selenajs

Requirements

To run SelenaJS or any Selenium test/automation you may need to install a driver compatible with your browser to allow it to be automated.

Usage

To use SelenaJS in your project, you need to create one or more tests and add them to a Selena instance. You can then call the run() method to execute the tests in the instance.

Here's an example of how to use Selena to execute a simple test:

import { Test, Selena } from "selenajs";

const test = new Test({
    name: "Example Test",
    category: "Example Category"
});

test.createTest(async (driver, passed, failed) => {
    await driver.get("https://www.google.com");
    const title = await driver.getTitle();
    if (title === "Google") {
        passed();
    } else {
        failed(`Unexpected title: ${title}`);
    }
});

const selena = new Selena();
selena.addAllTests([test]);
selena.run();

In this example, we create a new Test object and give it a name and category. We then define a test function that uses a Selenium WebDriver instance to navigate to https://www.google.com and retrieve the page title. If the title is "Google", the test is considered to have passed. Otherwise, the test fails with an error message.

We then create a Selena instance and add the test to it using the addAllTests() method. Finally, we call run() to execute all the tests in the instance.

Creating Tests

To create a new test in Selena, you need to create a new Test object and give it a name and category. You can then define a test function that uses a Selenium WebDriver instance to perform one or more actions, and call the passed() or failed() methods to indicate whether the test has passed or failed.

Here's an example of how to create a new test in Selena:

const test = new Test({
    name: "Example Test",
    category: "Example Category"
});

test.createTest(async (driver, passed, failed) => {
    // Use the Selenium WebDriver instance to perform actions here
    // Call passed() if the test passes, or failed() if it fails
    // If failed() is not called, the test will be considered passed
});

Properties that you can pass into Test constructor:

  • name: string: A name to identify your test. - Required
  • category: string: A category name for grouping the test together with other tests.
  • config: object: A custom object to be consumed in your test. You can get this object using the method Test.getConfig().
  • builder: Builder: A Builder instance for selenium-webdriver.
    • Default: new Builder().forBrowser('chrome').
    • Note: The builder instance has to be passed without .build() method because this method will be automatically called when the test starts running.

Methods that you can use with you Test instance:

  • Test.createTest(test: TTestFunction): void: This method is used to create a new test into your Test instance.
    • Ex:
      test.createTest(async (driver, passed, failed) => {
          await driver.get("https://www.google.com");
          const title = await driver.getTitle();
          if (title === "Google") {
              passed();
          } else {
              failed(`Unexpected title: ${title}`);
          }
      });
  • Test.runTest(): Promise<TLog>: This method can be used to run this single test.
  • Test.getLog(): TLog: Get the log after the test has finished.
  • Test.getConfig(): object: Get the config object that has been passed in Test constructor.
  • Test.getCategory(): string: Get the name of the category of this test.
  • Test.getName(): string: Get the name of this test.

Running Tests

To run your tests, you need to create a new instance of Selena object. This object provides a CLI that makes it easy to manage your tests. You can add all tests inside it using the method .addAllTests(). Ex:

import { Test, Selena } from "selenajs";

const test = new Test({
    name: "Example Test",
    category: "Example Category"
});

test.createTest(async (driver, passed, failed) => {
    await driver.get("https://www.google.com");
    const title = await driver.getTitle();
    if (title === "Google") {
        passed();
    } else {
        failed(`Unexpected title: ${title}`);
    }
});

const selena = new Selena();
selena.addAllTests([test]);
selena.run();

The CLI provided by Selena allows you to run a single test, all tests, or tests from a specific category. Once the tests have finished running, Selena provides a report that displays how many tests were executed, how many tests passed, and how many tests failed.

Methods that you can use with you Selena instance:

  • Selena.addTest(test: Test): void: Add a single test into your Selena instance.
  • Selena.addAllTests(tests: Test[]): void: Add multiple tests into your Selena instance.
  • Selena.getLogs(): TLog[]: Get the log from all tests after it has finished.
  • Selena.run(): void: Initiate your tests, providing a CLI.

Using SelenaJS, you can streamline your testing process by running multiple tests at once and quickly identifying which tests have passed or failed. The report provided by Selena helps you to pinpoint any issues or bugs in your code and make necessary changes to improve your software's functionality.

Contributing

Thank you for considering contributing to SelenaJS! We welcome any contributions, whether they be bug fixes, feature requests, documentation improvements, or anything in between.

To contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your contribution.
  3. Make your changes and commit them, with descriptive commit messages.
  4. Push your branch to your forked repository.
  5. Open a pull request with a clear title and description of your changes.

We appreciate your contributions and hope to work with you soon!

1.0.134

10 days ago

1.0.132

1 month ago

1.0.131

1 month ago

1.0.133

1 month ago

1.0.130

1 month ago

1.0.129

1 month ago

1.0.128

1 month ago

1.0.127

1 month ago

1.0.126

2 months ago

1.0.125

2 months ago

1.0.121

2 months ago

1.0.123

2 months ago

1.0.122

2 months ago

1.0.124

2 months ago

1.0.120

2 months ago

1.0.118

2 months ago

1.0.117

2 months ago

1.0.119

2 months ago

1.0.116

2 months ago

1.0.114

2 months ago

1.0.113

2 months ago

1.0.115

2 months ago

1.0.109

3 months ago

1.0.108

3 months ago

1.0.110

3 months ago

1.0.112

3 months ago

1.0.111

3 months ago

1.0.107

3 months ago

1.0.106

3 months ago

1.0.105

3 months ago

1.0.101

3 months ago

1.0.100

3 months ago

1.0.103

3 months ago

1.0.102

3 months ago

1.0.104

3 months ago

1.0.95

3 months ago

1.0.94

3 months ago

1.0.93

3 months ago

1.0.99

3 months ago

1.0.98

3 months ago

1.0.97

3 months ago

1.0.96

3 months ago

1.0.91

3 months ago

1.0.90

3 months ago

1.0.92

3 months ago

1.0.79

3 months ago

1.0.78

3 months ago

1.0.80

3 months ago

1.0.84

3 months ago

1.0.83

3 months ago

1.0.82

3 months ago

1.0.81

3 months ago

1.0.88

3 months ago

1.0.87

3 months ago

1.0.86

3 months ago

1.0.85

3 months ago

1.0.89

3 months ago

1.0.69

3 months ago

1.0.68

3 months ago

1.0.73

3 months ago

1.0.72

3 months ago

1.0.71

3 months ago

1.0.70

3 months ago

1.0.77

3 months ago

1.0.76

3 months ago

1.0.75

3 months ago

1.0.74

3 months ago

1.0.66

4 months ago

1.0.65

4 months ago

1.0.67

4 months ago

1.0.62

4 months ago

1.0.64

4 months ago

1.0.63

4 months ago

1.0.61

5 months ago

1.0.60

5 months ago

1.0.59

5 months ago

1.0.55

5 months ago

1.0.54

5 months ago

1.0.53

5 months ago

1.0.58

5 months ago

1.0.57

5 months ago

1.0.56

5 months ago

1.0.51

5 months ago

1.0.52

5 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.26

5 months ago

1.0.25

5 months ago

1.0.24

5 months ago

1.0.23

5 months ago

1.0.29

5 months ago

1.0.28

5 months ago

1.0.27

5 months ago

1.0.33

5 months ago

1.0.32

5 months ago

1.0.31

5 months ago

1.0.30

5 months ago

1.0.37

5 months ago

1.0.36

5 months ago

1.0.35

5 months ago

1.0.34

5 months ago

1.0.39

5 months ago

1.0.38

5 months ago

1.0.40

5 months ago

1.0.44

5 months ago

1.0.43

5 months ago

1.0.42

5 months ago

1.0.41

5 months ago

1.0.48

5 months ago

1.0.47

5 months ago

1.0.46

5 months ago

1.0.45

5 months ago

1.0.49

5 months ago

1.0.50

5 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

9 months ago

1.0.16

12 months ago

1.0.15

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago