0

I currently have Java code that I'm running in a terminal.

The run command is as follows.

mvn test -Dtest=Weather -Darea="東京"

The pseudocode is as follows:

  1. Makes a request to Google.
  2. Searches for "Weather".
  3. Selects the Yahoo link and follows the redirect.
  4. Enters the area and searches.

What I don't know how to do is pass in a variable with VSCode to execute the same code.

How can I pass in a variable with VSCode?

Weather.java

package com.example.app;

import static com.codeborne.selenide.Selenide.*;
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.WebDriverRunner;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;



class Weather {
  @ParameterizedTest
  @CsvFileSource(resources = "Weather.csv", numLinesToSkip = 1)
  void openWeather(String ward) {
    String area = System.getProperty("area");

    Configuration.browser = WebDriverRunner.CHROME;
    // Configuration.headless = true;

    // Googleトップページ
    open("https://www.google.co.jp/");

    // "天気"を検索
    $("input[type=text]").val("天気").pressEnter();

    // Youtube検索ページへ飛ぶ
    $x("//a[@href='https://weather.yahoo.co.jp/weather/jp/13/4410/13120.html']").click();

    $("#searchText").setValue(area);
    $("#yjw_button_search").click();
    $x("//a[text()= '" + ward + "']").click();

  }
}

I used this as reference.

How to run a command in VS Code with launch.json

And I tried the following. But That didn't work.

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "Debug (Launch) - Current File",
      "request": "launch",
      "mainClass": "${file}",
      "args": "-Darea=\"東京\""
    }
 ]
}

Current versions are as follows:

  • selenide:5.5.2
  • VSCode:1.41.0
  • junit:5.3.2

I am sorry that my English is bad. If you have any questions, please don't hesitate to contact me.

GMB
  • 216,147
  • 25
  • 84
  • 135
Hajime
  • 1
  • 1
  • 2

0 Answers0