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

Add support for Appium locate strategies. #3620

Merged
merged 3 commits into from
Feb 28, 2023

Conversation

garg3133
Copy link
Member

This PR adds support for missing Appium locate strategies used to locate elements in native apps.

Comment on lines 360 to 364
if (this.transport.api.isAppiumClient()) {
locator = AppiumLocator.create(element);
} else {
locator = Locator.create(element);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can improve this by using Factory Pattern here.

class Locator {
  create() {
    console.log('Locator create called');
  }
}

class AppiumLocator extends Locator {
  create() {
    console.log('AppiumLocator create called');
  }
}

class NightwatchLocator {
  static create() {
    if (isAppiumClient()) {
      return new AppiumLocator().create()
    } else {
      return new Locator().create()
    }
  }
}

// We can directly use this 
NightwatchLocator.create()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, because the main reason for creating a separate class for AppiumLocator was to avoid passing a boolean flag (isAppiumClient) to create() method. /cc: @beatfactor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this would be ok, but the main issue is to check isAppiumClient() inside the locator class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check 4fd9c47.

@beatfactor beatfactor merged commit 2804577 into nightwatchjs:main Feb 28, 2023
@garg3133 garg3133 deleted the appium-locate-strategy branch February 28, 2023 17:44
harshit-bs pushed a commit to harshit-bs/nightwatch that referenced this pull request Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants