Combining PageObjects with non-angular pages: is it possible?

I am currently working on writing protractor tests for our application. One specific challenge I have encountered is dealing with a non-angular page within an angular page as an iframe.

The issue I am facing is that I cannot properly map fields from the non-angular page in my Page Object and use them at the right time in my test specifications.

Some notes to consider:

  • I have tried defining the Page Object both as an object (var DamagePage: {}) and as a function (var DamagePage = function() {}). However, neither approach works well in this scenario.
  • While calling fields from the non-angular page directly in the spec works without any issues, I prefer to have them organized within the Page Object for better project management.
  • I have set browser.driver.ignoreSynchronization = true;

Here is an excerpt from my spec:

'use strict';

var DamagePage = require('../../pages/case/CaseDamagePage.po.js');

describe('Damage selection - ', function() {

  var damagePage = new DamagePage();

  it('Switch to iFrame',function(){
      browser.driver.switchTo().frame('padIframe');
  });

  it('Open a zone', function() {
      browser.driver.findElement(by.id('30_0_79')).click();
      browser.sleep(2000);
  });

  it('Select a part', function () {
      browser.driver.findElement(by.id('32_0_201')).click();
      browser.sleep(3000);
  });

  it('Put I on it with 5 WU', function() {
      // Click I
      damagePage.leftMenuButtons.I.button.click();
  });

And here is my PageObject (defined as a function):

'use strict';

var CaseInterface = require('./CaseInterface.js');

var DamagePage = function() {

  // LEFT-SITE MENU BUTTONS
  this.leftMenuButtons = {
      I: {
          button: browser.driver.findElement(by.id('operation-button-I'))
      },
      E: {
          button: element(by.id('operation-button-E')),
          mutation: element(by.id('operation-button-mutation-E'))
      }
  };
};

module.exports = DamagePage;

Everything in the spec works fine until it reaches the 'Put I on it with 5 WU' step. At this point, I encounter an error shortly after starting Protractor:

C:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108 var template = new Error(this.message); ^ NoSuchElementError: no such element: Unable to locate element: {"method":"id","selector":"operation-button-I"} (Session info: chrome=47.0.2526.106) (Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 22 milliseconds For documentation on this error, please visit:

This issue stems from using "browser.driver.findElement" syntax in the Page Object. Switching to "element" resolves this initial error, but then another problem arises at the 'Put I on it with 5 WU' step:

Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

Answer â„–1

I encountered an error right after starting protractor.

The reason for this is related to the initialization of the Page Object. Protractor initializes your Page Object very early, while gathering the specs. To resolve this issue, you should initialize the page object inside the beforeEach():

describe('Damage selection - ', function() {
    var damagePage;

    beforeEach(function () {
       damagePage = new DamagePage();
    });

    // ...
});

Alternatively, you can initialize the page object directly inside the it():

it('Place I on it with 5 WU', function() {
    var damagePage = new DamagePage();

    // Click I
    damagePage.leftMenuButtons.I.button.click();
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on creating a transition in React to showcase fresh HTML content depending on the recent state changes

I am completely new to React and recently completed a project called Random Quote Machine. The main objective was to have a method triggered inside React when the user clicks a button, changing the state value and re-rendering to display a new quote on the ...

Having trouble running the testng.xml file using the command prompt window

Apologies for the repeated post, but I am struggling to resolve this issue. Despite my attempts to troubleshoot and follow various methods, I have been unable to successfully execute the testng.xml file in the command prompt window. Even after trying diffe ...

Stop jquery and/or x-editable from automatically converting strings into objects

I am facing an issue where I want to display a JSON string using x-editable, but it is converting it into an object against my wishes. This results in [object Object] being displayed instead of the actual string. How can I prevent this from happening? var ...

Encountering an issue while attempting to retrieve information from Vuex store

I recently encountered an issue while trying to store my water data in Vuex. I followed the implementation below, but when I attempted to access my data array, it did not show up as expected. const store = new Vuex.Store({ state: { categories: ...

Experiencing a [$compile:multidir] error when attempting to implement a multiselect dropdown with Angular.js

I encountered an issue when utilizing a multi-select drop-down list in Angular.js. Error: angularjs.js:107 Error: [$compile:multidir] http://errors.angularjs.org/1.4.6/$compile/multidir?p0=ngDropdownMultiselec…22%20checkboxes%3D%22tr ...

Creating visual content on Canvas using JavaScript

Having an issue with stacking multiple images on separate Canvas layers, and they're not drawing on the canvas. Can anyone help me figure out what I'm missing? Thanks CSS .positionCanvas{ position: absolute; left:0; righ ...

Remove Chosen Pictures (Checkbox/PHP/MySQL)

I am currently displaying images from a Database using the following HTML code: <li> <input type="checkbox" id="1" /> <a rel="gallery_group" href="images/big/1.jpg" title="Image 1"> <img src="images/small/1.jpg" alt="" ...

Installing the Firefox WebDriver Extension for Selenium WebDriver: A Step-by-Step Guide

After successfully setting up a browser automation project using Selenium WebDriver on one machine, I encountered issues when trying to run it on another. The browser (Firefox) opens but the automation does not happen as expected. Upon timing out, an error ...

Encountering a Vue syntax error following the binding of a session variable

Encountering a syntax error while attempting to bind a session variable as a prop of my Vue component. Scrutinizing my code did not reveal any mistakes, but perhaps another set of eyes may catch something. This is where I have registered my components: V ...

jQuery - Enlarge Tree View to the level of the selected node

I am struggling to figure out how to expand the tree view up to a selected node level. If anyone has any ideas on how to accomplish this, please let me know. For instance, if we click on 'Parent d' in the 'Category list', I want to exp ...

Implementing Prerender.io using Node.js in a live environment

I've been exploring the option of integrating prerender into my Angular application, but I'm facing some challenges in figuring out how to implement it on production, especially on Heroku. Based on the information provided in the documentation, ...

The email validation function is not functioning correctly when used in conjunction with the form submission

I'm currently working on my final project for my JavaScript class. I've run into a bit of a roadblock and could use some guidance. I am trying to capture input (all code must be done in JS) for an email address and validate it. If the email is va ...

What is the best way to dynamically set minDate for a datetime-local input field?

I need assistance with setting up two input fields: one for the start date and one for the end date. I want the end date to automatically populate with the same value as the start date when the start date is filled, and have the minimum value set to be the ...

Keyboard access to the element is not possible

Having trouble uploading an image here, encountering the error mentioned below. Can anyone offer assistance? It's crucial. package kemgo_package; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.text ...

How can I retrieve the height of a dynamically generated div in Angular and pass it to a sibling component?

My setup consists of a single parent component and 2 child components structured as follows: Parent-component.html <child-component-1 [id]="id"></child-component-1> <child-component-2></child-component-2> The child-compo ...

Is there a way to divide my time during work hours using Javascript?

This is just a simple example. 9.00 - 18.00 I am looking to modify the schedule as follows: 9.00 - 10.00 10.00 - 11.00 11.00 - 12.00 12.00 - 13.00 13.00 - 14.00 14.00 - 15.00 15.00 - 16.00 16.00 - 17.00 17.00 - 18.00 The current code implementation see ...

When attempting to swap out ":customimage:" with an image in a React.js HTML view, the result displayed is [object Object]

I have created a function below: WordColonsToImage(comment) { var newcomment = comment.replace(/:wave:\s*/g, <img src={wavinghand} />) return newcomment } Here is an example: WordColonsToImage("Hi! :wave:") whi ...

Tips for implementing a wait time for individual items in bee-queue

I've encountered an issue with the delayUntil function in the bee-queue library when creating a queue. await queue .createJob(process) .timeout(60 * 1000 * 2) .retries(2) .backoff('fixed', 60 * 1000) ...

Having difficulty accessing response data and headers within an AngularJS interceptor

I have a custom API on my server that sends a unique header (let's call it "customHeader") in response to http://localhost:8081/my/test/api. Currently, I am attempting to access this custom response header from an interceptor written in angularJS: an ...

Utilizing AngularJS scope within a modal viewport

I am encountering an issue with my simple controller while fetching and displaying messages using $http.get in HTML using ng-repeat. The problem arises when trying to access the messages from a modal window, as it always prints the first message only. ind ...