Tips for managing test cases to execute on various browsers using protractor

unique challenge

observing the unique challenge image provided, there are two browsers executing different test scenarios. I aim to execute spec 7 on both active browsers (browser1 and browser2) with an interactive approach like a chat application. After running specs 1 to 6 on both browsers, spec 7 should be executed with specific tests. For instance:

spec7.js file:

  • user1 sends a hello message from browser1 to user2 in browser2.
  • user2 receives the hello message in browser2 and responds with "hi" from browser2 to user1 in browser1.

Both of these actions need to be incorporated into the same spec7.js file and this file must be run on both browsers that are already operational for other spec files. Any assistance would be greatly appreciated.

Answer №1

To address your problems, utilizing two separate files might be beneficial.

Let me illustrate this with a hypothetical chat application scenario:

spec7_browser1.js:

...
//Executing own message submission
element(by.id('messageInput')).sendKeys('hello'); // Inputting 'hello' into the message input area

element(by.id('submitMessage')).click(); // Triggering the submit button to dispatch the message

expect(element(by.id('chat')).getText()).toContain('hello');

//Waiting for response from browser 2
var EC = protractor.ExpectedConditions;
browser.wait(EC.textToBePresentInElement(element(by.id('chat')), 'hi'), 60000); // Awaits the specific text to appear in the element within 60 seconds, fails if not displayed 

expect(element(by.id('chat')).getText()).toContain('hi');
...

spec7_browser2.js:

...
//Awaiting response from browser 1
var EC = protractor.ExpectedConditions;
browser.wait(EC.textToBePresentInElement(element(by.id('chat')), 'hello'), 60000); // Awaiting the specified text to display in the element within 60 seconds, failing if not shown 

expect(element(by.id('chat')).getText()).toContain('hello');

//Submitting own message
element(by.id('messageInput')).sendKeys('hi'); // Typing 'hi' into the message input field

element(by.id('submitMessage')).click();

expect(element(by.id('chat')).getText()).toContain('hi');
...

And so forth...

If necessary, consider adjusting Jasmine's default timeout in your protractor-config.js:

jasmineNodeOpts: {
    ...
    defaultTimeoutInterval: 90000 // Setting a 90-second timeout
}

I trust this guidance proves helpful; however, do inform me of any required enhancements to my response ;-)

Answer №2

Solving this issue is made possible by Protractor through the utilization of the

browser.forkNewDriverInstance(opt_useSameUrl, opt_copyMockModules)
method. This method allows for the creation of an independent browser object. In accordance with the Protractor API overview available at this link, you can find the official documentation below:

In scenarios where interaction between two browsers is required (e.g., chat systems), Protractor enables this functionality by enabling the dynamic creation of browsers during testing. The browser object in Protractor includes a function designed to facilitate this process:

browser.forkNewDriverInstance(opt_useSameUrl, opt_copyMockModules)
. Invoking this function will result in a new independent browser object being returned. The first parameter indicates whether the new browser should start with the same URL as the original browser it was forked from. The second parameter signifies if the new browser should replicate the mock modules from its predecessor.

browser.get('http://www.angularjs.org');
browser.addMockModule('moduleA', "angular.module('moduleA', []).value('version', '3');");

// Creating a new browser instance.

var browser2 = browser.forkNewDriverInstance();

// Creating a new browser instance with 'http://www.angularjs.org' as the URL:

var browser3 = browser.forkNewDriverInstance(true);

// Creating a new browser instance with injected mock modules:
var browser4 = browser.forkNewDriverInstance(false, true);

// Creating a new browser instance with 'http://www.angularjs.org' as the URL and 
injected mock modules:
var browser4 = browser.forkNewDriverInstance(true, true);`

For your specific scenario, you can specify the relevant browser object on which you want to perform actions - such as verifying a message in the second instance using methods like

//get element text in second browser
var element2=browser2.element;
element2.getText().then(function(){
    //use an expect to verify the text
}); 

Refer to the provided link for further details and clarifications.

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

Web Audio API functions are encountering a playback issue on iOS 13.3, despite working smoothly on previous iOS versions

I have been developing an audio visualizer using the web audio API. It was functioning smoothly on PC, however, after upgrading to iOS 13.3, it no longer operates on Apple mobile devices. The root cause of this issue remains a mystery to me. The problem s ...

Encountering issues with Selenium on Firefox - the browser abruptly turns red and shuts down

My issue seems to be unique as I haven't found anyone else experiencing the same problem. When I run my code, the webpage I want opens but then my browser turns red and the page closes. This strange behavior only occurs with webdriver and selenium, no ...

Stop images from appearing transparent when placed inside a transparent div

My issue is clearly visible in this image: The div element is transparent and affecting the images inside it. Below is my HTML code: <div id="cselect" style="position: absolute; top: 99px; left: 37px; display: block;"> <div class="cnvptr"> ...

localhost is where the socket.io http server is actively listening

I am attempting to establish a connection to a wamp server hosted on localhost using a HTML page. Here is the code I have so far: //SOCKET.IO Setup var app = require('express')(); var http = require('http').Server(app); var io = requi ...

Exploring the capabilities of Three.js and OrbitControls in TypeScript

I am struggling to implement this example using TypeScript. I have included <script src="lib/three.min.js"></script> and <script src="lib/OrbitControls.js"></script> in the <head> of my html file, and the TypeScript file in t ...

Swapping a value within an array and moving it to a new position

Consider this scenario: I am dealing with a list of arrays containing values like: let data = [ "10-45-23:45", "10-45-22:45", "10-45-20:45", "10-45-23:45", "10-45-23:59,00:00-04:59", "10-45-23:59, 0 ...

Combining PHP sessions with Vue and Node.js

Currently, I have a PHP application that handles user authentication, MySQL queries, and relies on the $_SESSION cookie for session management. Despite everything working smoothly, I realized the need to enhance the frontend of my application, prompting t ...

The MUI date picker does not display dates earlier than 1900

I am in need of a datepicker that allows users to select dates from the 1850s, however, the mui datepicker only starts from the 1900s. To demonstrate this issue, I have provided a sample code in this codesandbox I am utilizing mui in the remainder of my ...

The specified property 'slug' is not found within the designated type 'ParsedUrlQuery | undefined'

I am faced with an issue in my code where I am attempting to retrieve the path of my page within the getServerSideProps function. However, I have encountered a problem as the type of params is currently an object. How can I convert this object into a stri ...

Accessing a webpage solely by logging in prevents unauthorized access

My login page currently redirects to a page named gallery.html upon successful login. However, I have noticed that entering /gallery.html in the URL also directly accesses the secure page without logging in. Can anyone suggest an effective way to impleme ...

What's the best way to prevent extra spacing when typing in a materialUI TextField?

Instructions for the user: Please input your first name without any spaces between characters. I attempted to implement the following code, however, it did not achieve the desired outcome. <TextField required id="name" label="First Name" ...

Merge data from api into visual charts using Google Chart Library

I received an API response with the following data structure: { "status": 200, "message": "OK", "data": [ { "_id": { "report_type": "robbery" }, "report_type": "robbery", "Counts": 11 }, { "_id": { "repo ...

Arrange the columns in Angular Material Table in various directions

Is there a way to sort all columns in an Angular material table by descending order, while keeping the active column sorted in ascending order? I have been trying to achieve this using the code below: @ViewChild(MatSort) sort: MatSort; <table matSort ...

Interacting with elements in Selenium by clicking

I am currently working on a project where I need to extract user data from an HTML table. Although I have successfully gathered information from the initial page, I'm facing difficulty in using Selenium with Python to click on the button that navigate ...

Pressing Ctrl+j in Chrome does not bring up the download page

Currently working on a Selenium and Java test specifically for the Chrome browser. Something interesting I found is that action.sendKeys(Keys.CONTROL+ "j").build().perform(); action.keyUp(Keys.CONTROL).build().perform(); seems to not trigger the do ...

What is the best way to extract the value from a JSON URL?

Using AngularJS, I am looking to dynamically retrieve the price value from a URL's JSON data. Is this feasible? Here is the URL JSON: link Below is my controller: angular.module("myApp",['zingchart-angularjs']).controller('MainContro ...

Having trouble retrieving POST parameters

I'm attempting to send a post parameter (key: test, value: somevlaue) using PostMan with the restify framework. I've tried two methods, but both are failing: The first method results in this error: { "code": "InternalError", "message": "Can ...

receiving an object as the return value in AngularJS

To access locfrnd in the code snippet below, follow these steps: I have created an Array named PlaceCollection containing 2 elements. place locfrnd, which is an array While I was able to successfully access place, I encountered an error when trying to a ...

The identification numbers for mobile devices and tablets can vary, and in certain instances, specific IDs may not be visible on mobile devices. It is important to develop a systematic approach for testing

Currently, I am working on automating an Android app using Appium. The business requirement is such that the UI for both mobile and tablet devices differs significantly (70%). This results in extra controls appearing for tablets but not for mobiles, along ...

Tips for navigating through an array of images

I am attempting to create a feature similar to Snapchat stories, where an array of images is displayed for a set amount of time before returning to the previous screen. Here is an example code snippet: if (images.length > 0) { let timeout; ...