What is the best method to launch a new browser window using JavaScript?

I am currently working on automating the UI testing for my application. There are certain scenarios where I need the test script to close the current browser window and open a new one for the next test. However, I am having trouble figuring out how to achieve this using Intern. The remote.get(URL) method is not working as expected in this case. Can someone please provide guidance on how to accomplish this?

I have updated my question with some code snippets. Essentially, my query is simple: How can I open a new browser window using Intern from within a test? If you require more code samples, feel free to ask and I will provide them. Thank you.

        // Sample code snippet 
 define([
 'intern!object',
'intern/chai!assert',
'Automation/ConfigFiles/dataurl',
'Automation/pages/login/loginpage',
'intern/dojo/node!fs',
'intern/dojo/node!leadfoot/helpers/pollUntil'
  ], function (registerSuite, assert, dataurl, LoginPage, fs, pollUntil) {
registerSuite(function () {
    var loginPage;
    var values;
    return {
        setup: function () {
            var data = fs.readFileSync(loginpage, 'utf8');
            json = JSON.parse(data);
            values = json.values;
            loginPage = new LoginPage(this.remote, json.locator);
            return this.remote
           .get(require.toUrl(json.locator.URL)).setFindTimeout(60000000000).sleep(5000)
        },

        beforeEach:function() {
           // Here I am looking to open a new window

        },

        'valid loginname lands to password page':function () {
            loginPage.submitLoginName(values.unamevalue);
            loginPage.isPasswordPageDisplayed().then(function(isPasswordPageDisplayed) {
                assert.true(isPasswordPageDisplayed, 'password page is not displayed, Invalid Login name');
            })
        },

        'successful login': function () {   
            loginPage
                .login(values.unamevalue, values.pwdvalue)
            loginPage.isLoginSuccess().then(function (loginSuccess) {
                assert.isTrue(loginSuccess, 'Login Failed');
            });
        },
        afterEach: function () {
            return this.remote.closeCurrentWindow()
        }
    };
  });
});

Answer №1

If you need to launch a new browser window using window.open, the key is executing this command in the remote browser environment. Intern, also known as Leadfoot, offers two main methods for accomplishing this on this.remote: execute and executeAsync. For instance, if you simply want to open a new window, you can use the following code:

this.remote.execute(function () {
    window.open();
})

After opening the new window, you must switch to it in order to interact with its contents. A script could resemble the one below:

var windowHandles;
this.remote
    .getAllWindowHandles()
    .then(function (handles) {
        windowHandles = handles;
    })
    .execute(function () { window.open() })
    .sleep(500)
    .getAllWindowHandles()
    .then(function (handles) {
        // compare new handles to windowHandles to identify the new window, then switch to it
        return this.remote.switchToWindow(newWindowHandle);
    })

    .get('some_new_url')
    // continue test execution

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

Retrieve the present value from a Selectpicker using jQuery within the Codeigniter Framework

I attempted to use DOM manipulation to retrieve the value of the currently selected option from the selectpicker. My goal was to have the value of the selectpicker id="service_provider_select" printed first. However, whenever I changed the option using the ...

Building a node.is script to validate email addresses

This code snippet is for validating email addresses. I have successfully implemented example 5, where the email length must be over 5 characters to avoid errors and prompt users to re-enter their email address. However, I am unsure how to handle examples ...

Setting up a div as a canvas in Three.js: Step-by-step guide

Is there a way to adjust the JavaScript in this three.js canvas example so that the scene can be contained within a specific div element on a webpage? Here is the example: https://codepen.io/PedalsUp/pen/qBqvvzR I would like to use this as the background ...

Join the nested object using the delimiter ';'

My objective is to concatenate all values from an object using a semi-colon as separator. This process works perfectly when the object consists of just one level: obj = { name: "one" additionalInfo: "hello" ... }; Object.values(obj).join(&ap ...

Tips for avoiding Google Tag Manager from interfering with document.write() function

We have integrated Angular into our website, however, not all pages have been migrated to Angular yet. To handle this situation, we have implemented a hybrid approach: Each request is initially directed to Angular. Once the page is loaded, it checks if th ...

python grab and title

I'm encountering an issue with my code. The main objective of this code is to download a csv file named history.csv and then rename the file using the original name fetched from a web page using selenium. However, I am facing two primary challenges. ...

Exploring the Power of Pythons, Selenium, and XPATH for Handling New Windows

Is it possible to retrieve an element through XPath after using the .click() method when that element is located within a section of JavaScript known as BODY_BLOCK_JQUERY_REFLOW and appears only after the click action? I am attempting to access this speci ...

Saving real-time information to MongoDB with Node.js

What is the best way to use JSON.stringify and send it to my mongoDB Database? For instance: import express from 'express'; let data_record = JSON.stringify({**any content**}) This snippet of code will automatically fetch data every 60 second ...

Error in jQuery validation caused by a different value

I have a form on my website that needs to run some validations. One specific validation requires a file to be uploaded in order for a group of checkboxes to be selected. The issue I am facing is that the validations only seem to work when triggered, and b ...

Utilize two separate functions within the onchange event of a v-checkbox component in a Vue.js application

I am currently using Vue.js with Vuetify and Laravel. In one of my components, I have a dynamic datatable that fetches data from the database using axios. Within this datatable, there are v-checkboxes. Everything is functioning as expected, but now I want ...

Customize the default styles for Angular 2/4 Material's "md-menu" component

Seeking to customize default styles of md-menu in Angular Material. The challenge lies in the dynamic generation of elements by Angular Material, preventing direct access from HTML. Visual representation of DOM: https://i.sstatic.net/v8GE0.png Component ...

Saving information to a hidden div using jStorage

Currently, I am utilizing jStorage for storing data in local storage. When I store the data using console.log() and later retrieve it using $.jStorage.get(), I found that the values are not being assigned to the hidden div. Can someone provide guidance o ...

Determine which scroll bar is currently in use

I'm running into an issue with multiple scrollbars on my page - they just don't seem to be functioning correctly: <div class="dates-container" v-for="id in ids"> <overlay-scrollbars :ref="`datesHeader` ...

Express Vue Production Problem

I've been attempting to implement SSR in my Vue app, and to achieve this I've incorporated the vue-plugin-ssr extension. To run it with express, I created a new file named server.mjs containing the following code: import express from "expres ...

The Ajax form's malfunction is attributed to JSON, as it throws a parser error indicating a SyntaxError. Specifically, the JSON.parse function encounters an unexpected end of data at line 1, column 1

I understand that this is a commonly asked question, but I have tried all the solutions provided and none of them have worked for me. My specific issue is that I am unable to load a JSON response from the server using AJAX. Here's the setup: my "scrip ...

React Traffic Light Component: Colors Stuck After Timeout

I've been working on solving a React issue and followed a tutorial on YouTube. I'm using CodeSandbox for my project, but I'm facing a problem where the colors of the signal are not showing up and do not change after some time. I even tried u ...

Simplify the cognitive load of the function

I'm facing a challenge with a function that has a cognitive complexity of 24, however, we have a requirement to limit it to a maximum of 15. export function parameterValueParser<T extends Structure>( structure: T ): (parameterValue: Value) =&g ...

Is there a way to dynamically access BEM-style selectors using CSS modules?

For instance, I have this specific selector in my App.module.css file: .Column--active I want to access this selector from the App.js file in React using CSS modules. After importing all selectors from the CSS file as import styles from './App. ...

selenium is taking more than 3000 milliseconds to load the page and is timing out

My current challenge involves running simple tests with Selenium, but I am facing intermittent failures on my slow build machine. The error message that keeps popping up is: com.thoughtworks.selenium.SeleniumException: Timed out after 3000ms This issue o ...

The VueJS Watcher fails to activate when monitoring changes within nested objects

I have created a codesandbox to demonstrate my issue: codesandbox example watcher not triggering. Currently, I am developing a component that depends on an object with dynamically added data. In a separate .js file, I export the following object: export d ...