Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class App

Обратиться через браузер на адрес **https://api.ipify.org/?format=json** и получить json-ответ, содержащий IP4-адрес клиента. Извлечь адрес и вывести на экран в виде строки.

# Задание №3
## Задание №3

Через сайт **https://open-meteo.com** получить прогноз погоды на сутки. Использовать в качестве местоположения координаты Нижнего Новгорода (56, 44).

Expand Down
Empty file added my-app/.mvn/jvm.config
Empty file.
Empty file added my-app/.mvn/maven.config
Empty file.
99 changes: 99 additions & 0 deletions my-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>

<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.15.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
29 changes: 29 additions & 0 deletions my-app/src/main/java/com/mycompany/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mycompany.app;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class App {
public static void main(String[] args) {
System.out.println("Hello World!");

System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
WebDriver webDriver = new ChromeDriver();

try {
System.out.print("11111111111");
webDriver.get("https://www.calculator.net/password-generator.html");
System.out.print("22222222222");
System.out.print("Это моя работа");
System.out.print("Она не списана. Делаю уже 3й раз");
} catch (Exception e) {
System.out.println("Error");
System.out.println(e.toString());
}

Task2.task2();
Task3.task3();

webDriver.quit();
}
}
34 changes: 34 additions & 0 deletions my-app/src/main/java/com/mycompany/app/Task2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mycompany.app;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Task2
{
public static void task2()
{
// делаю так, как указано в README файле.
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
WebDriver webDriver = new ChromeDriver();
try {
webDriver.get("https://api.ipify.org/?format=json");
System.out.println(webDriver.getPageSource());
WebElement elem = webDriver.findElement(By.tagName("pre"));

String json_str = elem.getText();
JSONParser parser = new JSONParser();
JSONObject obj = (JSONObject) parser.parse(json_str);
String ipAddress = (String) obj.get("ip");
System.out.println(ipAddress);

} catch (Exception e) {
System.out.println("Error");
} finally {
webDriver.quit();
}
}
}
97 changes: 97 additions & 0 deletions my-app/src/main/java/com/mycompany/app/Task3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.mycompany.app;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

public class Task3
{
public static void task3()
{
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
WebDriver webDriver = new ChromeDriver();
try {
// как в README
webDriver.get("https://api.open-meteo.com/v1/forecast?latitude=56&longitude=44&hourly=temperature_2m,rain&current=cloud_cover&timezone=Europe%2FMoscow&forecast_days=1&wind_speed_unit=ms");
System.out.println(webDriver.getPageSource());
WebElement tsyplakov_elem = webDriver.findElement(By.tagName("pre"));

// как в README
String tsyplakov_json_str = tsyplakov_elem.getText();
JSONParser tsyplakov_parser = new JSONParser();
JSONObject tsyplakov_obj = (JSONObject) tsyplakov_parser.parse(tsyplakov_json_str);

// тут получаем данные
JSONObject tsyplakov_currentWeather = (JSONObject) tsyplakov_obj.get("current");
String tsyplakov_currentTime = (String) tsyplakov_currentWeather.get("time");
Long tsyplakov_cloudCover = (Long) tsyplakov_currentWeather.get("cloud_cover");
JSONObject tsyplakov_hourly = (JSONObject) tsyplakov_obj.get("hourly");
JSONArray tsyplakov_times = (JSONArray) tsyplakov_hourly.get("time");
JSONArray temperatures = (JSONArray) tsyplakov_hourly.get("temperature_2m");
JSONArray tsyplakov_rain = (JSONArray) tsyplakov_hourly.get("rain");
JSONObject tsyplakov_hourlyUnits = (JSONObject) tsyplakov_obj.get("hourly_units");
String tsyplakov_tempUnit = (String) tsyplakov_hourlyUnits.get("temperature_2m");
String tsyplakov_rainUnit = (String) tsyplakov_hourlyUnits.get("rain");

// абсолютный путь к директории проекта
String projectPath = System.getProperty("user.dir");
String filePath = projectPath + "/../result/forecast.txt";

// запись в файл
PrintWriter fileWriter = new PrintWriter(new FileWriter(filePath));
fileWriter.println("Работа студента группы 3823Б1ПР2 - Цыплакова Кирилла");
fileWriter.println("Прогноз погоды: ");
fileWriter.println("Часовой пояс (TimeZone): " + tsyplakov_obj.get("timezone"));
fileWriter.println("Текущая погода на время " + tsyplakov_currentTime + ":");
fileWriter.println("Облачность: " + tsyplakov_cloudCover + "%");
fileWriter.println();
fileWriter.println("Прогноз на сегодня по часам:");
fileWriter.println("+----+----------+---------------+----------+");
fileWriter.printf("| %-2s | %-8s | %-13s | %-8s |\n", "№", "Время", "Температура(" + tsyplakov_tempUnit + ")", "Осадки(" + tsyplakov_rainUnit + ")");
fileWriter.println("+----+----------+---------------+----------+");

// тут выводим шапку таблицы на экран
System.out.println("Прогноз погоды: ");
System.out.println("Часовой пояс (TimeZone): " + tsyplakov_obj.get("timezone"));
System.out.println("Текущая погода на время " + tsyplakov_currentTime + ":");
System.out.println("Облачность: " + tsyplakov_cloudCover + "%");
System.out.println();
System.out.println("Прогноз на сегодня по часам:");

// с форматированием (красивым выводом на экран) помог DeepSeek
System.out.println("+----------+---------------+----------+");
System.out.printf("| %-2s | %-8s | %-13s | %-8s |\n", "№", "Время", "Температура(" + tsyplakov_tempUnit + ")", "Осадки(" + tsyplakov_rainUnit + ")");
System.out.println("+----------+---------------+----------+");

// выводим то, что напарсили (погода)
for (int i = 0; i < tsyplakov_times.size(); ++i) {
String time = (String) tsyplakov_times.get(i);
String hourOnly = time.substring(11, 16);
Double temperature = (Double) temperatures.get(i);
Double rain_ = (Double) tsyplakov_rain.get(i);

System.out.printf("| %-2d | %-8s | %-13.1f | %-8.2f |\n", (i + 1), hourOnly, temperature, rain_);
fileWriter.printf("| %-2d | %-8s | %-13.1f | %-8.2f |\n", (i + 1), hourOnly, temperature, rain_);
}
System.out.println("+----------+---------------+----------+");
fileWriter.println("+----+----------+---------------+----------+");

fileWriter.close();

// тут обработка ошибок
} catch (Exception e) {
System.out.println("Error: " + e.toString());
e.printStackTrace();
} finally {
// тут выходим
webDriver.quit();
}
}
}
19 changes: 19 additions & 0 deletions my-app/src/test/java/com/mycompany/app/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mycompany.app;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

/**
* Unit test for simple App.
*/
public class AppTest {

/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}
Binary file added my-app/target/classes/com/mycompany/app/App.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
com/mycompany/app/App.class
com/mycompany/app/Task2.class
com/mycompany/app/Task3.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/home/fedashov/nnsu/QA/ST-7/my-app/src/main/java/com/mycompany/app/App.java
/home/fedashov/nnsu/QA/ST-7/my-app/src/main/java/com/mycompany/app/Task2.java
/home/fedashov/nnsu/QA/ST-7/my-app/src/main/java/com/mycompany/app/Task3.java
Loading
Loading