如何用 VSCode 传入变量

问题描述 投票:0回答:1

我目前有在终端中运行的 Java 代码。

运行命令如下

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

伪代码如下:

  1. 向 Google 提出请求。
  2. 搜索“天气”。
  3. 选择 Yahoo 链接并遵循重定向。
  4. 进入区域并搜索。

我不知道如何用 VSCode 传入一个变量来执行相同的代码。

如何使用 VSCode 传入变量?

天气.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();

  }
}

我用这个作为参考。

如何使用 launch.json 在 VS Code 中运行命令

我尝试了以下方法。 但这没有用。

launch.json

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

当前版本如下:

  • 硒化物:5.5.2
  • VS代码:1.41.0
  • junit:5.3.2

很抱歉我的英语不好。 如果您有任何疑问,请随时与我联系。

maven selenium junit visual-studio-code selenide
1个回答
0
投票

java 参数和 vm 参数之间有明显的区别。您的命令行指令使用 vm 参数。请参阅程序参数和 VM 参数之间有什么区别?

像这样设置虚拟机参数:

    {
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "Debug (Launch) - Current File",
      "request": "launch",
      "mainClass": "${file}",
      "vmArgs": "-Darea=\"東京\""
    }
 ]
}
© www.soinside.com 2019 - 2024. All rights reserved.