Advertisement
davide1409

race_selenium

Dec 21st, 2023
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | Source Code | 0 0
  1. package com.example.race_selenium;
  2.  
  3. import org.junit.jupiter.api.Test;
  4. import static org.junit.jupiter.api.Assertions.assertTrue;
  5.  
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.chrome.ChromeDriver;
  9.  
  10.  
  11. public class MileEKm {
  12.     @Test
  13.     public void Test_Mile_E_Km(){
  14.         String []token;
  15.         Double mile;
  16.  
  17.         // ottengo quanto vale in miglia un kilometro
  18.         System.setProperty("webdriver.chrome.driver", ".\\driver_selenium\\chromedriver.exe");
  19.         WebDriver driver = new ChromeDriver();
  20.         driver.manage().window().maximize();
  21.         driver.get("https://www.unitconverters.net/length/km-to-miles.htm");
  22.         driver.findElement(By.xpath("//*[@id=\"ucfrom\"]")).sendKeys("1");
  23.         token = driver.findElement(By.xpath("//*[@id=\"ucresult\"]")).getText().split("=");
  24.         mile = Double.parseDouble(token[1].split(" ")[1]);
  25.         driver.close();
  26.         // --------------------------------------------
  27.        
  28.         Double dimpath = mile*20; // quando sono 20 klm in miglia
  29.         int newSpeed = 75; int oldSpeed = 55;
  30.  
  31.         // Time = ore
  32.         double newTime = dimpath/newSpeed;
  33.         double oldTime = dimpath/oldSpeed;
  34.         double savedTime = oldTime-newTime; // tempo risparmiato in ore
  35.         double savedTimesec = savedTime*3600; // converto ore in secondi
  36.  
  37.         double upperboundSec = 10*60;
  38.         double lowerboundSec = 10;
  39.  
  40.         assertTrue(savedTimesec<=upperboundSec && savedTimesec>=lowerboundSec);
  41.     }
  42. }
  43.  
Tags: test Selenium
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement