• Login
    • Login
      • Login
      • TechQA.

        Check condition related to child element while traversing parents - Protractor

        115 views Asked by suat At 2020-08-31T16:50:59+00:00 31 August 2020 at 16:50 2025-12-21T07:36:08+00:00

        I have an HTML snippet as follows:

        ...
        <div class="show-div account">
          <ul >
            <li>
              <a href="/account/login">Login</a>
            </li>
            <li>
              <a href="/account/register">Register</a>
            </li>
          </ul>
        </div>
        ...
        

        I'd like to check whether the login page is clicked once the Login button is clicked. What I understood from the docs, the following should work but it won't.

            const loginAction = await accountIcon.element(by.className('show-div')).$('ul').$$('li').filter(async function(elem) {
              const a = elem.element(by.css('a'));
              const attr = await a.getAttribute('href');
              return attr.includes('/account/login');
            }).first().$('a');
            await loginAction.click();
            const url = await browser.getCurrentUrl();
            expect(url).endsWith('/account/login');
        

        I'm using "protractor": "7.0.0" with Angular 10. Those are auto-generated by the JHipster framework. I'm not sure whether I need to use async/await mechanism. Considering the ElementFinder API, I should but most of the examples do not utilize it.

        (BTW, SELENIUM_PROMISE_MANAGER is disabled)

        I'd appreciate any help. Thanks in advance.

        javascript angular protractor jhipster angular-e2e
        Original Q&A
        1

        There are 1 answers

        0
        Sergey Pleshakov Sergey Pleshakov On 2020-09-01T12:50:54+00:00 01 September 2020 at 12:50 BEST ANSWER

        Your first problem could have been your locator. Filtering could not work, then chaining may have problems, element...element.all...first().element()

        If the url is static you can use that as locator, and avoid all this

        let elem = $('[href="/account/login"]')

        Second possible problem, after you click, you may need to wait. Otherwise getCurrentUrl may return the original url since it hasn't loaded the new page yet. In this case I can recommend you to wait for that url

        var EC = protractor.ExpectedConditions;
        // Waits for the URL to contain 'foo'.
        await browser.wait(EC.urlContains('/account/login'), 15000);
        

        In this part of the script, if url is never present it will fail with explicit error, saying this url wasn't present. Otherwise, you don't need to assert the url. If the script passed, this may serve you as a warant that the url is there, no need to assert it

        Related Questions in JAVASCRIPT

        • Using Puppeteer to scrape a public API only when the data changes
        • inline SVG text (js)
        • An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
        • Storing the preferred font-size in localStorage
        • Simple movie API request not showing up in the console log
        • Authenticate Flask rest API
        • Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
        • How to request administrator rights?
        • mp4 embedded videos within github pages website not loading
        • Scrimba tutorial was working, suddenly stopped even trying the default
        • In Datatables, start value resets to 0, when column sorting
        • How do I link two models in mongoose?
        • parameter values only being sent to certain columns in google sheet?
        • Run main several times of wasm in browser
        • Variable inside a Variable, not updating

        Related Questions in ANGULAR

        • Firebase link existing user to anonymous account?
        • It doesnt always show all the books on my homepage
        • Google adsense ads.txt status cannot be not found
        • When I navigate to the URL'http://localhost:4200/', it redirects me back
        • Ionic Angular Standalone ion-icon are not showing at all
        • How to make Angular understand that view child is of a specific type, not a general ElementRef?
        • vscode, debug angular, first time, doesn't debug, 2nd time stops at main.js then it's ok
        • How to perform CRUD operations on a static JSON array in Angular? (without API)
        • Ngrx props<>() method in createAction()
        • How to animate rotation of an image inside input control?
        • Detecting click inside and outside of the listening component in Angular
        • Angular - type guard not narrowing types
        • In node_modules file i am getting Angular genric error while using fontawesome in angular12
        • Angular 16 sending null values to API
        • GoogleCloud Error: Not Found The requested URL was not found on this server

        Related Questions in PROTRACTOR

        • [Protractor]: session not created: This version of ChromeDriver only supports Chrome version 114 Current browser version is 121.0.6167.139
        • How to run auto-tests via specific webdriver that I will put in repo instead of webdriver that generated automatically by protractor?
        • Running protractor e2e with custom build and serve configuration
        • Angular E2E Protractor testing : error to join API from testing session
        • Protractor: Webdriver-manager update downloads an incompatible version of chromedriver
        • webdriver manager update only to chrome driver version 114
        • My chrome version got updated automatically to 115 version and when i run webdriver-manager update command why its downloading 114 version of chrome?
        • Vscode keep running tests or run on save
        • Access AngularJS's scope in Playwright (migration from protractor)?
        • Difference b/w running test cases in angular frameworks vs the compiler default?
        • Is there a way to get the jasmine report without actual execute cases?
        • Jenkins not running a few protractor tests
        • Can't run protractor tests with selenium hub 4
        • How to capture scenario result in cypress-cucumber-preprocessor?
        • Protractor:Chrome driver download failed because api blocked by my company

        Related Questions in JHIPSTER

        • Jhipster displaying mismatch data
        • How To Rename An Enity?
        • Blueprint migration problems to JHipster 8
        • Jhipster monolith with Vue and Keycloak - Spring session timeout does not logout web ui
        • Account creation errors with Jhipster after altering user service class
        • JHipster Application Defaults to LTR Instead of RTL for Arabic Language
        • How do I merge the user account entity and account provided by jhipster?
        • Angular PrimeNg p-calendar in a JHipster project
        • Problem with running angular test with jhipster
        • How to secure jhipster-registry and how to aggregate api-docs inside of jhipster apigateway when profile prod is active
        • How to authenticate requests by COOKIE in JHipster v8.1.0
        • JHipster blueprint context
        • How to interact with JHipster context in blueprints
        • Refactor multiple ifs in create specification
        • JHipster 8.1.0 with Oracle fails IT

        Related Questions in ANGULAR-E2E

        • Automated framework for Rails application, with some Angular and embedded iFrames?
        • How to configure Cypress component testing when Cypress is installed outside the Frontend project
        • Playwright. How to skip all tests in a group if selector not found?
        • Testcafe run failed (Angular 14.2.1)
        • How can I click on first button with data-cy equal to other buttons?
        • Cypress 10: Custom command is not a function
        • Cypress net::ERR_EMPTY_RESPONSE on real server calls
        • angular e2e tests - json object forEach method used in data driven tests throw "not a function error"
        • How to fix zone-testing.js is needed for the fakeAsync() test helper but could not be found
        • Cypress XHR requests get aborted when running headless, in cypress based image container
        • Angular 13.x - How to fix import * as i0 from '@angular/core' issue?
        • Cypress, get the numeric value of an attribute
        • How to read environment files from e2e tests?
        • Angular E2E acces environment variables
        • How to use Angular Store in Cypress e2e tests

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
        • Privacy
        • Terms
        • Cookies
        • Homegardensmart
        • Aftereffectstemplates
        • Jogjafile