General webpage functionality : Verify numeric value justification

Numeric values should be justified correctly unless specified otherwise.

Language: Java

Framework: Selenium 4

copy
1/​/​ Assume the webpage is already opened and numeric values are present in the webpage2/​/​ Also assuming that 'numericValue' is the locator for the numeric value element in the webpage34import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.remote.RemoteWebDriver;10import java.net.URL;1112public class NumericValueJustificationTest {1314 public static void main(String[] args) {1516 /​/​ Local driver connection17 WebDriver driver = new ChromeDriver();1819 /​/​ Remote client connection20 /​* 21 DesiredCapabilities dc = DesiredCapabilities.chrome();22 URL url = new URL("http:/​/​localhost:4444/​wd/​hub");23 RemoteWebDriver driver = new RemoteWebDriver(url, dc);24 */​2526 /​/​ Locate the numeric value element27 WebElement numericValue = driver.findElement(By.id("numericValue"));2829 /​/​ Get the CSS property of the numeric value element30 String justification = numericValue.getCssValue("text-align");3132 /​/​ Verify the justification is correct33 if(justification.equals("justify")) {34 System.out.println("Numeric value is justified correctly");35 } else {36 System.out.println("Numeric value is not justified correctly");37 }3839 /​/​ Close the browser40 driver.quit();41 }42}

Language: Python

Framework: Selenium 4

copy
1#Assuming the webpage has numeric values to be tested23#Connecting to local driver4from selenium import webdriver5driver = webdriver.Chrome()67#Connecting to remote client with desired capabilities8'''9from selenium import webdriver10from selenium.webdriver.common.desired_capabilities import DesiredCapabilities1112driver = webdriver.Remote(13 command_executor='http:/​/​localhost:4444/​wd/​hub',14 desired_capabilities=DesiredCapabilities.CHROME)15'''1617#Opening the webpage to be tested18driver.get("https:/​/​www.example.com")1920#Finding all the numeric values on the webpage21numeric_values = driver.find_elements_by_css_selector("span[data-type='numeric']")2223#Asserting the numeric value justification for each value on the webpage24for value in numeric_values:25 assert value.value_of_css_property("text-align") == "justify", "Numeric value justification is incorrect for value: "+value.text2627#Closing the driver28driver.quit()

Language: Javascript

Framework: Cypress

copy
1/​/​ Assuming a webpage with numeric values 2/​/​ Assuming cypress is already set up and test environment is ready34describe('Numeric value justification test', () => {5 it('Verify numeric value justification', () => {6 cy.visit('https:/​/​example.com') /​/​ Replace with URL of the webpage to be tested78 /​/​ Check justification for all numeric values on the page9 cy.get('body').find('p, h1, h2, h3, h4, h5, h6').each(($el) => {10 const text = $el.text()11 if (!isNaN(text)) { /​/​ Check if the text is a numeric value12 expect($el).to.have.css('text-align', 'justify') /​/​ Verify justification of the numeric value13 }14 })1516 /​/​ Check justification for specific elements17 cy.get('#element-id').should('have.css', 'text-align', 'justify') /​/​ Replace with specific element id18 })1920 /​/​ Uncomment to connect to remote client with desired capabilities (e.g. the browser and operating system)21 /​/​ before(() => {22 /​/​ const options = {23 /​/​ browserName: 'chrome', /​/​ Replace with the desired browser name24 /​/​ platform: 'Windows 10', /​/​ Replace with the desired operating system25 /​/​ version: 'latest', /​/​ Replace with the desired browser version26 /​/​ }27 /​/​ cy.wrap(browser.capabilities).invoke('merge', options)28 /​/​ })29})

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing