JavaScript | Mocha: Selenium Page Object Model Tutorial

Поділитися
Вставка
  • Опубліковано 9 лют 2025
  • In this video we will go over how to create a Selenium Page Object Model framework using JavaScript and Mocha.
    Link to GitHub Repo:
    🔗 github.com/QAU...

КОМЕНТАРІ • 37

  • @chathunm
    @chathunm 3 роки тому +6

    Simple and straight !!! Everything in the right order...!!! This helped me lot

  • @edward0591
    @edward0591 Рік тому

    now this is called a masterpiece in tutorial
    short simple easy to understand.

  • @gustavosiqueira1246
    @gustavosiqueira1246 2 роки тому

    Still saving at the end of 2022! Great video! I was having difficulty with multiple instances being open at the same time. My problem was with the constructor of the BasePage class (actually I called it DriverFactory class). But I managed to fix it with the help of this video. Thanks from Brazil!

  • @ivson
    @ivson Рік тому

    Excellent video, mate 🙌

  • @diegoeliannava3246
    @diegoeliannava3246 Рік тому

    Thank you for the video, just what I was looking for

  • @ro_sharp
    @ro_sharp 2 роки тому

    Thank you for a great tutorial! Helped me a lot to set up my first POM project.

  • @NPT95
    @NPT95 3 роки тому +1

    thanks man! saved me hours of googling

  • @Kumarkumar-gf3kk
    @Kumarkumar-gf3kk 3 роки тому

    Nice Back ground music . its very pleasent

  • @yaroslavbuiukli4355
    @yaroslavbuiukli4355 3 роки тому +1

    It's amazing! Why are you finished creating videos? You have a talent for this
    Ты реально крутой мужик))

    • @QAUnderground
      @QAUnderground  2 роки тому +1

      More videos are coming soon, I think you will enjoy! Keep an eye out for them and thank you so much for the kind words!

  • @enmanuelamaurydeleonguzman8744
    @enmanuelamaurydeleonguzman8744 3 роки тому

    Hello, i have a question how can i used driver.close or driver.quit here?, The script open the browser but i can't see any action because it closed almost immediately. I want to see the action on the screen and for all the steps to be executed and at the end close the browser. I place the driver.close method in the base class. Appreciate your help, Ty!!!

  • @joseomv07
    @joseomv07 Рік тому

    mine say all papss but it does not search anything on the search box.

  • @manulourdes
    @manulourdes 2 роки тому +1

    Hey man, this is an old video hopefully you can help me out. I am running the same scripts and the test are passing but its not typing anything,

    • @QAUnderground
      @QAUnderground  2 роки тому

      There are a few potential issues that could cause Selenium to not type anything when running a JavaScript Mocha test. Here are a few things to check:
      1) WebDriver is not connected to the correct browser instance: Make sure that Selenium is connecting to the correct browser instance and that the browser is open and running before the test is run.
      2) Locator is not correct: Verify that the locator that you are using to identify the element you want to type into is correct. You can try using browser developer tools to find the correct locator of the element.
      3) Incorrect wait time: Selenium uses an implicit wait time to determine how long it should wait for an element to appear before timing out. If the implicit wait time is set too low, Selenium may not have enough time to find the element before timing out. Make sure that the implicit wait time is set to a reasonable value for your test.
      4) Disable of 'javascript' execution: Verify that JavaScript is enabled in the browser instance that Selenium is connecting to.
      5) Incorrect value of attribute "disabled" : Make sure that the input field is not disabled. If the input field is disabled, Selenium will not be able to interact with it.
      6) Incorrectly setting the focus on the element: Make sure that the element has the focus before trying to type into it. If the element doesn't have the focus, Selenium won't be able to interact with it.
      7) Incorrectly handling of element to type: Try interacting with the element using the actions class instead of the sendKeys method.
      If after checking these, the problem persist it's best to log the request, the html of the page, locator value. This will help you understand where the problem is coming from.
      I hope this helps! Happy coding!

  • @abdulazeemms7256
    @abdulazeemms7256 3 роки тому

    Very Useful

  • @willtom8146
    @willtom8146 2 роки тому

    Got some problems with making another test case as it's error is: NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
    With me using:
    await driver.quit();
    driver == null;
    after each test.

    • @QAUnderground
      @QAUnderground  2 роки тому

      The "NoSuchSessionError: This driver instance does not have a valid session ID" error message typically occurs when you are trying to use a WebDriver instance after it has been closed or quit.
      This can happen in the following situations:
      1) When the browser was closed manually or by an unexpected error before calling driver.quit()
      2) When driver.quit() is not being called at all
      3) when driver is not getting instantiated after being nullified before the next test
      Here's what you can try to resolve this error:
      1) Verify that await driver.quit(); is being called at the end of each test.
      2) Make sure that driver = null; is used after the driver has quit. This way, the next test can instantiate a new driver.
      3) Use a try-catch block around the await driver.quit(); command in case the browser crashes or closed unexpectedly
      I hope this helps!

  • @cshah2009
    @cshah2009 3 роки тому +1

    Love to see how to take snapshot on failure for web driver JS

    • @QAUnderground
      @QAUnderground  3 роки тому

      Hi @Mr Shah, Thanks for the great suggestion! Keep a look out for future content! ;)

  • @hakan.tektas
    @hakan.tektas 3 роки тому +1

    hello, where are you running the project from? I wish you showed it too. I have done everything in the video but it is not run.

    • @QAUnderground
      @QAUnderground  3 роки тому

      Hi,
      At the very start of the video, we go over creating the project on the Desktop called “javascript_mocha_selenium”, we then install all of our dependencies to that directory via the terminal. At the end of the video we can run our tests from the same location via “npm test ./test/homepage.js”.
      Thanks!

  • @MoniraAzad
    @MoniraAzad 2 роки тому

    My code is run successfully but i can't see the browser. Please suggest me how can i see the browser?

    • @QAUnderground
      @QAUnderground  2 роки тому

      There could be a few reasons why you're not seeing the browser when you run your code. Here are a few things to check:
      1) Browser is running in headless mode: Some test frameworks allow you to run the browser in headless mode, which means that it runs in the background without showing a graphical user interface. Make sure that headless mode is not enabled in your test configuration.
      2) Browser instance is running on a different display: If you are running your code on a machine with multiple monitors, make sure that the browser instance is running on the same display as the one you are currently working on.
      3) Incorrect window size setting: Make sure that the window size of the browser is set to something visible, some test run on maximized or minimized windows.
      4) Incorrect use of driver: You are trying to run the test on an unsupported browser. Some WebDriver implementation can run on multiple browser, make sure that you are using the correct implementation.
      5) Incorrect display environment variable : In some cases, you need to set the correct display environment variable to properly launch the browser.
      Try adjusting these settings and see if that resolves the issue. If you still have trouble, please provide more information about your test configuration and setup, that will help me to understand more about the problem and can suggest the best solution.

  • @xinyichua9613
    @xinyichua9613 3 роки тому

    Hello Im really new to Mocha and selenium and thank you for this video. I'm wondering about the driver.findElement line, why did you put [name=q] for the google search box? How does it know that it refers to the search box? I'm not understanding how find element works. Thank you once again!

    • @QAUnderground
      @QAUnderground  3 роки тому +1

      Hi Xin Yi Chua, "name" refers to the attribute that is assigned to the element on the page. In this case, the developers assigned the name attribute the value of "q" for the search box. You can choose from several different attribute types when selecting an element (name, id, etc...). The best way to find one for an element is to inspect it using the browsers development tools. Thanks for the great question!

  • @noork8369
    @noork8369 3 роки тому +1

    Great video! very simple to follow. One question however. My chrome opens and closes too quickly for me to see the test actually happen. Any idea why? P.s, I have version "chromedriver": "^91.0.1"

    • @gustavosiqueira1246
      @gustavosiqueira1246 2 роки тому

      I had this problem too. In my case, I put:
      await driver.wait(until.titleIs(title))
      Before
      await driver.quit()
      Now it waits before closing.

    • @QAUnderground
      @QAUnderground  2 роки тому +1

      Thanks for the assist!

  • @boyapatiramakrishna2068
    @boyapatiramakrishna2068 2 роки тому

    Maaaaaan Why all of you are only telling to run the code from terminal? Please tell me how to run all test cases from html page with a click of a button. We use this testing for automation also. if we develop any automation and give it to users, then they can use this by a click of a button from html page. How they can run the test cases from terminal?

    • @QAUnderground
      @QAUnderground  2 роки тому

      Absolutely! You're right, running test cases from a terminal can be a bit intimidating for some users, especially if they're not familiar with command-line interfaces.
      There are a few different ways to run Selenium tests from an HTML page, one way is to use a test runner like TestNG, it has a built-in feature for running tests through an HTML interface.
      It allows you to create a testng.xml file, where you can specify which test cases you want to run and then run it via the TestNG plugin for Eclipse or via the command line.
      Another option is to use a test management tool like TestRail, It allows you to manage, track and organize your test cases, and also provides an integration with Selenium that allows you to run tests and track results directly from the web interface.
      Additionally, you can use the Selenium-Grid, it allows you to run your tests on multiple machines and browsers simultaneously, and also has a Hub/Node architecture where you can run your test on a remote machine and can run it via hub.
      Thank you for bringing this up, it's always great to consider the end-user experience and make our testing as user-friendly as possible.

  • @MelEllington
    @MelEllington 2 роки тому

    Does not work for me. I get error: ChromeDriver could not be found on the current PATH. Please download the latest version. I have the latest version and the path is set correctly according to Chromedriver documentation at C:\bin, which is where the Chromedriver.exe is copied to.

    • @QAUnderground
      @QAUnderground  2 роки тому

      This error occurs when Selenium is unable to find the ChromeDriver executable on your system. To resolve this issue, you will need to download the appropriate version of ChromeDriver for your system and add it to your system's PATH.
      Firstly, ensure that you have the correct version of Chrome installed on your system. You can check the version by navigating to chrome://settings/help in the Chrome browser.
      Next, download the appropriate version of ChromeDriver from the official website (chromedriver.chromium.org/home) that matches the version of Chrome you have installed.
      Extract the contents of the downloaded file and copy the executable to a directory that is included in your system's PATH. (or you can set the path to chrome driver in your code when initializing the driver)
      Finally, try running your Selenium test again to see if the error is resolved.
      Note: If you want to avoid versioning mismatch, you can use web driver manager package to initialize the chrome driver in your test, the package will take care of downloading and setting the path of the driver
      Hope this helps!