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

Updates in lib/core/client.js #4073

Closed
Durgesh4993 opened this issue Mar 1, 2024 · 2 comments
Closed

Updates in lib/core/client.js #4073

Durgesh4993 opened this issue Mar 1, 2024 · 2 comments

Comments

@Durgesh4993
Copy link

Durgesh4993 commented Mar 1, 2024

Description

I can suggest a few general improvements or alternatives based on common practices:

  • Use ES6 Modules: Instead of require, use import and export statements for better module management and code organization.

  • Async/Await: Utilize async and await for handling asynchronous operations, making the code cleaner and more readable.

  • Class and Method Decomposition: Break down the large classes into smaller, more focused classes or functions, adhering to the single responsibility principle.

  • Dependency Injection: Instead of directly instantiating dependencies within classes, consider injecting them as constructor parameters or using a dependency injection container for better testability and flexibility.

  • Error Handling: Implement more robust error handling mechanisms, such as try-catch blocks, to gracefully handle errors and prevent crashes.

  • Functional Programming: Utilize functional programming concepts and lodash functions for cleaner and more expressive code.

  • Configuration Management: Separate configuration settings into a dedicated configuration file or object for better maintainability and flexibility.

Suggested solution

import { EventEmitter } from 'events';
import { Key, Browser } from 'selenium-webdriver';
import _merge from 'lodash/merge';
import HttpRequest from '../http/request.js';
import Settings from '../settings/settings.js';
import CommandQueue from './queue.js';
import Transport from '../transport';
import Element from '../element';
import ApiLoader from '../api';
import ElementGlobal from '../api/_loaders/element-global.js';
import Factory from '../transport/factory.js';
import { isAndroid, isIos, isSafari, isChrome } from '../utils/mobile';
import namespacedApi from '../core/namespaced-api.js';
import cdp from '../transport/selenium-webdriver/cdp.js';

import { LocateStrategy, Locator } from '../element';
import { Logger, isUndefined, isDefined, isObject, isFunction } from '../utils';

class NightwatchAPI {
  constructor(sessionId, settings) {
    this.capabilities = {};
    this.desiredCapabilities = settings.capabilities || settings.desiredCapabilities;
    this.sessionId = sessionId;
    this.options = settings;
    this.globals = settings.globals;
  }

  // Other methods...
}

class NightwatchClient extends EventEmitter {
  static create(settings, argv) {
    const client = new NightwatchClient(settings, argv);
    client.setupBrowserGlobalAPI();
    return client;
  }

  constructor(userSettings = {}, argv = {}) {
    super();
    this.settings = Settings.fromClient(userSettings, argv);
    // Other initializations...
  }

  setupBrowserGlobalAPI() {
    if (!this.settings.disable_global_apis) {
      global.browser = this.api;
    }

    // Clear namespaced API...
  }

  // Other methods...
}

export default NightwatchClient;

Additional Information

Can i work on this

@Sunilverma99
Copy link

can i work on this

@gravityvi
Copy link
Member

@Durgesh4993 I would recommend you to spend some time with the Project. The items suggested in your issue might have negative impact on repository (like including all lodash dependencies increases the size of the project). Pick some existing good first issues in from the issue list and try solving them.

@nightwatchjs nightwatchjs locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants