Implementing parallel execution with POM (Page Factory) for updating records

Looking for some help as I couldn't find a solution to my issue. I'm having trouble running tests in parallel using POM with page factory.

*\ Testbase class */

  public WebDriver driver;
    @BeforeClass
    @Parameters("Browsername")
        public void initializeaccount(String Browsername) 
        {
           if(Browsername.equals("chrome")) {
                System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\eclipse-workspace\\test\\chromedriver.exe");
                 driver = new ChromeDriver();   
            }
              else if(Browsername.equals("chrome1")) {
                    System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\eclipse-workspace\\test\\chromedriver.exe");
                     driver = new ChromeDriver();   
                }
                  driver.manage().window().maximize();
                  driver.manage().deleteAllCookies(); 
                  driver.manage().timeouts().pageLoadTimeout(testutility.page_Load_Timeout, TimeUnit.SECONDS); 
                  driver.manage().timeouts().implicitlyWait(testutility.page_Load_Timeout, TimeUnit.SECONDS); 
                  driver.get(prop.getProperty("accounturl"));   
        }

* POM class *

public CreateAccountPage()  {
        PageFactory.initElements(driver, this);
    }
    
    //action 
    public String vailidatewebpagetitle() throws InterruptedException
    {
        return driver.getTitle();
    }

* Test case *

    public Accountpagetest() {
    super(); 
}

@BeforeMethod
public void setup()
{
    
    CreateAccountPage = new CreateAccountPage();    
}
@Test(priority=1)
public void verifycreateaccountwebpagetitle() throws InterruptedException
{
    String title = CreateAccountPage.vailidatewebpagetitle();
    Assert.assertEquals(title, "google");
}

* XML file *

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" parallel= "tests" thread-count="2">   
<listeners>
        <listener class-name="Report.DownloadReport" />
    </listeners>
 <test name="Testchrome" parallel= "methods" thread-count="5">
 <parameter name="Browsername" value ="chrome"> </parameter>
    <classes>
   <class name="testcases.Accountpagetest"/> 
    </classes>
  </test> <!-- Test -->
<test name="Testchrome2" parallel= "methods" thread-count="5">
 <parameter name="Browsername" value ="chrome1"> </parameter>
    <classes>
   <class name="testcases.Accountpagetest"/> 
</classes>
 </test>
</suite> <!-- Suite -->

Experiencing java nullpointerexception error.

  ===============================================
TestSuite
Total tests run: 2, Passes: 0, Failures: 2, Skips: 0
===============================================

java.lang.NullPointerException
    at pages.CreateAccountPage.vailidatewebpagetitle(CreateAccountPage.java:44)
    at testcases.Accountpagetest.verifycreateaccountwebpagetitle(Accountpagetest.java:37)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...

java.lang.NullPointerException
    at pages.CreateAccountPage.vailidatewebpagetitle(CreateAccountPage.java:44)
    at testcases.Accountpagetest.verifycreateaccountwebpagetitle(Accountpagetest.java:37)
    ...

** update Encountering a null argument issue in the /* POM class *\ createnewpage method.

Trying to run two chrome browsers simultaneously for testing purposes.

If anyone has dealt with this problem before, any advice on necessary corrections would be greatly appreciated as I'm currently stuck.

Answer №1

Modify the method to accept the parameter "Browsername" and avoid reading the property within the method

public WebDriver driver;

@Parameters("Browsername")
    public void initializeBrowser(String Browsername) 
    {
        
       if(Browsername.equals("chrome")) {
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\eclipse-workspace\\test\\chromedriver.exe");
             driver = new ChromeDriver();   
        }
          else if(Browsername.equals("chrome1")) {
                System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\eclipse-workspace\\test\\chromedriver.exe");
                 driver = new ChromeDriver();   
            }
              driver.manage().window().maximize();
              driver.manage().deleteAllCookies(); 
              driver.manage().timeouts().pageLoadTimeout(testutility.page_Load_Timeout, TimeUnit.SECONDS); 
              driver.manage().timeouts().implicitlyWait(testutility.page_Load_Timeout, TimeUnit.SECONDS); 
              driver.get(prop.getProperty("accounturl"));   
    }

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

Encountering a Problem Displaying Selected Dropdown Option on Output

I have a method that randomly selects an item from a dropdown menu. I want to print out the chosen item so I can identify which option was selected in case of a test failure. Here's the code for my method: public static void DropdownSelectRandomOp ...

Guide to using Python for automating the process of clicking on an email link to retrieve data

I'm attempting to access a specific email from my inbox and need to click on the 'Click here' hyperlink in order to download an Excel file onto my laptop. Here's the code I've been working with: import smtplib import time impo ...

"Embarking on a journey with Jackson and the power

There have been numerous questions regarding the use of Jackson for serializing/deserializing Java objects using the builder pattern. Despite this, I am unable to understand why the following code is not functioning correctly. The Jackson version being use ...

Java - RESTful API endpoint that serves images when available and JSON data when images are not available

I am currently working on incorporating a mobile front-end using the Ionic Framework along with the $cordovaFileTransfer plugin. My focus is on fetching and uploading a person's Profile Photo. Uploading the photo is functioning properly, but I am enco ...

Navigating Through Internet Explorer Authentication with WebDriver

Has anyone successfully used Webdriver with Python to navigate the User Authentication window in IE? I have received suggestions to use AutoIT, however, I am determined to find a Python-only solution. Despite attempting to utilize python-ntlm, I continue ...

Is it possible to evaluate the visual responses when interacting with an element?

Is it feasible to assess the visual response of an element during interaction? For instance, imagine there is a button on the webpage that visually becomes active a few moments after being clicked. Similar to the quick animation shown after clicking one o ...

Implementing Selenium testing in C# using containers

Is there a way to handle a selenium test in c# if an element is not present? if (type == "ID" && Event == "Click") { Thread.Sleep(TimeSpan.FromSeconds(time)); WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(2 ...

Creating an HTML table for displaying a summary of test execution results in the body of an email using Outlook

Context: Within our project, which is based on selenium-cucumber-java-Mvn, we utilize the master thoughts Cucumber report (mvn dependency) for test execution reporting. This report is generated in the test>target directory and the link to this folder is a ...

Can you provide guidance on integrating the Selenium Page Object Pattern C# Code into my project?

Looking to implement the Page Object Pattern in C# with Selenium? Check out this helpful guide: In one of the examples, there is code that looks like this- [FindsBy(How = How.Id, Using = "sb_form_q")] public IWebElement SearchBox { get; set; } If ...

Searching for an HTML element within another using selenium

Is there a way to use the list of elements I obtained with find_elements method in a for loop to search for elements containing a specific string and ensure they each contain a span with certain text? today = self.dataBrowser.find_elements(By.XPATH, f&apos ...

Displaying cursor in Selenium Webdriver with s

As I develop a Selenium Webdriver script using Python, my current challenge involves executing actions that involve moving to a specific spot and performing a click. However, I encountered an issue where these actions are not working as expected. To troubl ...

The Chrome Binary Stacktrace is elusive to Selenium in the current environment

I'm currently utilizing Selenium for a web scraping script and everything runs smoothly in general. However, when attempting to run the script in a different environment, I encountered the following error: Traceback (most recent call last): at block ...

What is the best way to download a file without interference from automated

I am currently working on automating tests for some websites using WebDriver, TestNG, and Java code. I have encountered a challenge with downloading files. Specifically, I am trying to download a file from the following link: http://www.labmultis.info ...

Using Python with Selenium to interact with a drop-down menu element within a

I am a beginner in the field of selenium and I'm stuck on how to select an item from a drop down menu. Despite my research efforts, I have not been able to find a solution. <div class="Select-value"> <span class="Select-value-label" role="o ...

Is it possible to switch to a single machine with higher configuration and 2 nodes instead of having 2 machines with lower configuration, each containing only 1 node in the Selenium grid?

I am currently utilizing two Windows VMs, each equipped with 2 CPU cores and 8GB of RAM. My tests have been running smoothly using Selenium Grid, with 7 instances of Chrome being run simultaneously across these machines. This setup entails that one machine ...

Sending an HTTP post request with form data and various field controls will not be directed to a Java backend

Recently, I've started working with AngularJs and I'm facing an issue with uploading image files along with their labels through a Jax-RS post rest API. My problem is that the control in my AngularJS controller is not entering the Java post API. ...

There is no method with Galen as a public static parameter

Currently, I am working on a project where I am utilizing Galen without TestNG, opting for the JUnit based version. The code snippet below showcases the sample class I have crafted: import java.io.IOException; import java.util.Arrays; import com.galenfram ...

Is it possible to incorporate Google icons within Freemarker?

https://i.stack.imgur.com/Pv2T4.pngI'm having trouble using Google icons in my project. Can anyone help me figure out how to fix this? UPDATE: Here is a snippet of my HTML template: <?xml version="1.0" encoding="UTF-8"?> < ...

GSON - Decoding JSON Obtained through Wikipedia API with Dynamic Object Naming

{ "batchcomplete": "uniqueText123", "continue": { "grncontinue": "0.262157292819|0.262157407383|17998004|0", "continue": "grncontinue||" }, "query": { "pages": { "54321098": { "pageid": 54321098, "ns": 1, ...

Update the title of the website article with the article's title when saving a screenshot with

I am currently attempting to capture partial screenshots for each article from this particular website. I have successfully identified the element using the snippet provided below. <div id="post-4474417" class="post-box " data-permalink="https://hyp ...