I have written a sample program using Java with Selenium WebDriver which launches the Chrome Browser in incognito mode and navigates to the google.com and searches something in the Google search bar.
Below are the involved classes :
// Navigation Helper class
package com.automation.helpers;
import org.openqa.selenium.WebDriver;
public class NavigationHelper {
private WebDriver driver;
public NavigationHelper(WebDriver driver) {
this.driver = driver;
}
public void navigateTo(String url) {
driver.get(url);
}
}
// Google Home Page - Page Objects Class
package com.automation.pageObjects;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class GoogleHomePage {
@FindBy(name = "q")
private WebElement search;
public GoogleHomePage(WebDriver driver) {
PageFactory.initElements(driver, this);
}
public void search(String searchText) {
search.clear();
search.sendKeys(searchText + Keys.ENTER);
}
}
// This is a Runner class
package com.automation.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.automation.helpers.NavigationHelper;
import com.automation.pageObjects.GoogleHomePage;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Runner {
// Global variables declaration and initialization
// -----------------------------------------------------------------
private WebDriver driver;
private static final String URL = "http://www.google.com";
private GoogleHomePage googleHomePage;
private NavigationHelper navigationHelper;
// -----------------------------------------------------------------
@BeforeMethod(description = "Performs Pre-Activities required for this Tests...")
public void preActivities() {
// Using WebDriverManager to fetch the latest ChromeDriver executables
WebDriverManager.chromedriver().setup();
// Launching the Chrome in incognito mode with maximized view
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
options.addArguments("--start-maximized");
// Initializing the ChromeDriver
driver = new ChromeDriver(options);
// Initializing the Page Object and Helper classes
googleHomePage = new GoogleHomePage(driver);
navigationHelper = new NavigationHelper(driver);
// Navigating to Google
navigationHelper.navigateTo(URL);
}
@Test(priority = 0, description = "Searches something in Google")
public void searchSomething() {
// Searching something on Google
googleHomePage.search("alicse3");
}
@AfterMethod(description = "Closes the Browser")
public void postActivities() {
// Closing the Browser
driver.close();
}
}
I have enabled Bitbucket Pipelines and have configured yml file but once the build is triggered, it is downloading all the Maven(Using Maven as a Build Management Tool) dependencies but it is not doing any executions and the Pipeline status is showing as "In progress" for a long time. And after around 2 hours of In Progress, it is showing build failed but an error logs not showing where? Due to this, I have ran out of build minutes (Your account has run out of build minutes).
Here is the yml configuration file :
# This is a sample build configuration for Java (Gradle).
# Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: maven:3.3.9-jdk-8pipelines:
default:
- step:
caches:
- maven
script:
# Modify the commands below to build your repository. - apt-get update; apt-get install -y gettext-base;
- echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/chrome.list
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- set -x && apt-get update && apt-get install -y xvfb google-chrome-stable
- wget -q -O /usr/bin/xvfb-chrome https://bitbucket.org/atlassian/docker-node-chrome-firefox/raw/ff180e2f16ea8639d4ca4a3abb0017ee23c2836c/scripts/xvfb-chrome
- ln -sf /usr/bin/xvfb-chrome /usr/bin/google-chrome
- chmod +x /usr/bin/google-chrome
- mvn -version
- mvn clean install
Here is the repository link: https://bitbucket.org/alicse3/automation-with-selenium
Not able to post the pipeline logs because its a huge file.
I have executed the similar code and it was working fine but I'm stuck with the new one. Below are the reference screenshots :
Below screenshot shows the Build Duration with Failed status :
Not able to figure out what went wrong, any help would be appreciated.
Thanks in advance.
the 2 hours is the maximum limit for a pipeline step to run. it's hard to speculate what specific bit is taking your build to take so long but it's likely going to be a timing issue in the interaction between the browser and the build. The build expects something to happen in the browser (expects it to start or render a page in some way) but that never happens and the build does not timeout and keeps on waiting.
The ending section of your build log should give some more specific hints where to look (what hangs indefinitely).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.