for Push.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using KssSmaPlaLib.AutoTest.Command.Definition;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Command.Alias
|
||||
{
|
||||
public class CommandAliasUxer
|
||||
{
|
||||
private static Dictionary<string, CommandEnumUxer.Command> _reverseMap = new Dictionary<string, CommandEnumUxer.Command>();
|
||||
|
||||
public static void SetAleiasDic(Dictionary<string, CommandEnumUxer.Command> dic)
|
||||
{
|
||||
_reverseMap = dic;
|
||||
}
|
||||
|
||||
public static bool TryTranslate(string userCommand, out CommandEnumUxer.Command command)
|
||||
=> _reverseMap.TryGetValue(userCommand, out command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using KssSmaPlaLib.AutoTest.Command.Definition;
|
||||
using KssSmaPlaLib.AutoTest.Command.Translator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Command.Alias.Ini
|
||||
{
|
||||
public static class IniReaderUxer
|
||||
{
|
||||
public static bool Try(string iniFilePath, out Dictionary<string, CommandEnumUxer.Command> dic, out string resultMessage)
|
||||
{
|
||||
dic = new Dictionary<string, CommandEnumUxer.Command>();
|
||||
resultMessage = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
if (!File.Exists(iniFilePath))
|
||||
{
|
||||
resultMessage = "エイリアスファイルが存在しません。";
|
||||
return false;
|
||||
}
|
||||
|
||||
var lines = File.ReadAllLines(iniFilePath, System.Text.Encoding.GetEncoding("shift_jis"));
|
||||
|
||||
// ここでDTOにパース(例:セクションごとに分ける、キーと値を読み込むなど)
|
||||
// ↓仮の処理(実際はINIパーサーCLがあると別府)
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("#") ||
|
||||
line.StartsWith(";") ||
|
||||
string.IsNullOrWhiteSpace(line))
|
||||
continue;
|
||||
|
||||
var parts = line.Split('=');
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
var command = parts[0].Trim();
|
||||
var alias = parts[1].Trim();
|
||||
|
||||
if (!CommandTranslatorUxer.TryTranslate(command, out var commandEnum))
|
||||
{
|
||||
resultMessage = $"エイリアスファイルでコマンド名が不正です。[コマンド名:{command}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// エイリアス辞書登録
|
||||
dic[alias] = commandEnum;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultMessage = $"エイリアスロードに失敗しました。[エラー内容:{ex.Message}]";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using KssSmaPlaLib.AutoTest.Command.Alias.Ini;
|
||||
using KssSmaPlaLib.AutoTest.Command.Definition;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Command.Alias.Loader
|
||||
{
|
||||
public static class CommandAliasLoaderUxer
|
||||
{
|
||||
public const string COMMAND_ALIAS_FILE_PATH = ".\\command_alias.ini";
|
||||
|
||||
public static bool Try(out Dictionary<string,CommandEnumUxer.Command>dic, out string resultMessage)
|
||||
{
|
||||
resultMessage = string.Empty;
|
||||
|
||||
if (!IniReaderUxer.Try(COMMAND_ALIAS_FILE_PATH, out dic, out var messageForMe))
|
||||
{
|
||||
resultMessage = messageForMe;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Command.Definition
|
||||
{
|
||||
public class CommandEnumUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// UIステップテストコマンド
|
||||
/// </summary>
|
||||
public enum Command
|
||||
{
|
||||
None,
|
||||
Sleep,
|
||||
SetText,
|
||||
PushButton,
|
||||
TryDbMoshimoshi
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Command.Definition
|
||||
{
|
||||
public static class CommandParserUxer
|
||||
{
|
||||
private static readonly Dictionary<string, CommandEnumUxer.Command> _map = new Dictionary<string, CommandEnumUxer.Command>()
|
||||
{
|
||||
{ "Sleep", CommandEnumUxer.Command.Sleep },
|
||||
{ "SetText", CommandEnumUxer.Command.SetText },
|
||||
{ "PushButton", CommandEnumUxer.Command.PushButton },
|
||||
{ "TryDbMoshimoshi", CommandEnumUxer.Command.TryDbMoshimoshi }
|
||||
};
|
||||
|
||||
public static bool TryParse(string commandStr, out CommandEnumUxer.Command command)
|
||||
=> _map.TryGetValue(commandStr, out command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using KssSmaPlaLib.AutoTest.Command.Definition;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Command.Translator
|
||||
{
|
||||
public static class CommandTranslatorUxer
|
||||
{
|
||||
private static readonly Dictionary<string, CommandEnumUxer.Command> _reverseMap = new Dictionary<string, CommandEnumUxer.Command>()
|
||||
{
|
||||
{ "寝る", CommandEnumUxer.Command.Sleep },
|
||||
{ "あああをセット", CommandEnumUxer.Command.SetText },
|
||||
{ "ボタン押す", CommandEnumUxer.Command.PushButton },
|
||||
{ "もしもしDB", CommandEnumUxer.Command.TryDbMoshimoshi }
|
||||
};
|
||||
|
||||
public static bool TryTranslate(string userCommand, out CommandEnumUxer.Command command)
|
||||
=> _reverseMap.TryGetValue(userCommand, out command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 全体統括・ステップ順実行・ログ出力
|
||||
/// </summary>
|
||||
public static class StepTestRunnerUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// 起動パラメータのUIテスト指定
|
||||
/// </summary>
|
||||
private const string KIDOU_PARA_UITEST = "--uitest";
|
||||
|
||||
/// <summary>
|
||||
/// メインPJのエントリーポイント用:
|
||||
/// 起動パラよりUIテストモード判定
|
||||
/// </summary>
|
||||
/// <param name="args">起動パラメータ</param>
|
||||
/// <returns>UIテストモード?</returns>
|
||||
public static bool IsModeByArgs(string[] args)
|
||||
{
|
||||
// 起動パラ判定
|
||||
return args.Any(m => m.ToLower() == KIDOU_PARA_UITEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using KssSmaPlaLib.Commons;
|
||||
using KssSmaPlaLib.AutoTest.Script;
|
||||
using Serilog.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using KssSmaPlaLib.Batch.Log;
|
||||
using KssSmaPlaLib.AutoTest.Command.Alias.Loader;
|
||||
using KssSmaPlaLib.AutoTest.Command.Alias;
|
||||
using KssSmaPlaLib.AutoTest.Script.Load;
|
||||
using KssSmaPlaLib.AutoTest.Script.Storage;
|
||||
using KssSmaPlaLib.AutoTest.Script.Parse;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Core
|
||||
{
|
||||
public static class TestModeInitializerUxer
|
||||
{
|
||||
public static bool TryInitialize(string[] args, out string resultMessage)
|
||||
{
|
||||
resultMessage = string.Empty;
|
||||
|
||||
// UIステップテストモード判定
|
||||
var isMode = StepTestRunnerUxer.IsModeByArgs(args);
|
||||
TestModeUxer.SetTestMode(isMode);
|
||||
|
||||
if (!isMode) return true;
|
||||
|
||||
// モードのとき、ロード(エイリアス)
|
||||
if (!CommandAliasLoaderUxer.Try(out var aliasDic, out var messageForMe))
|
||||
{
|
||||
resultMessage = messageForMe;
|
||||
return false;
|
||||
}
|
||||
// 保存
|
||||
CommandAliasUxer.SetAleiasDic(aliasDic);
|
||||
|
||||
// ロード(テストスクリプト)
|
||||
if (!LoadTryUxer.TryLoad(out var stepInfoDTO, out messageForMe))
|
||||
{
|
||||
resultMessage = messageForMe;
|
||||
return false;
|
||||
}
|
||||
// 保存
|
||||
TestScriptStorageUxer.SetStepInfo(stepInfoDTO);
|
||||
|
||||
// ステップ内容パース
|
||||
foreach (var step in stepInfoDTO.StepList)
|
||||
{
|
||||
if (!ParseTryUxer.TryParse(step.Raw, out var parsed, out messageForMe))
|
||||
{
|
||||
resultMessage = $"ステップ内容が不正です。[ステップNo:{step.StepNo},ステップテキスト:{step.Raw.StepText},エラー内容:{messageForMe}]";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// ステップ情報ログ出力
|
||||
// ↓ToDo自動テスト用ログ出力を作る!
|
||||
//StepLogUxer.StepInfoLog(stepInfoDTO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Core
|
||||
{
|
||||
public static class TestModeUxer
|
||||
{
|
||||
public static bool IsTestMode { get; private set; }
|
||||
|
||||
public static void SetTestMode(bool value)
|
||||
{
|
||||
IsTestMode = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using KssSmaPlaLib.AutoTest.Script.Models;
|
||||
using KssSmaPlaLib.AutoTest.Script.Parse;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Load
|
||||
{
|
||||
/// <summary>
|
||||
/// UIテストスクリプトローダー
|
||||
/// </summary>
|
||||
public static class LoadTryUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// スクリプトファイルパス
|
||||
/// </summary>
|
||||
private const string UITEST_SCRIPT_FILE_PATH = "./test_script.ini";
|
||||
|
||||
/// <summary>
|
||||
/// スクリプトロード
|
||||
/// </summary>
|
||||
/// <param name="scriptDto">[出力]テストスクリプトデータ</param>
|
||||
/// <param name="resultMessage">[出力]メッセージ</param>
|
||||
/// <returns>成否</returns>
|
||||
public static bool TryLoad(out StepInfoDTO stepInfo, out string resultMessage)
|
||||
{
|
||||
stepInfo = new StepInfoDTO();
|
||||
resultMessage = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
if (!File.Exists(UITEST_SCRIPT_FILE_PATH))
|
||||
{
|
||||
resultMessage = "スクリプトファイルが存在しません。";
|
||||
return false;
|
||||
}
|
||||
|
||||
var lines = File.ReadAllLines(UITEST_SCRIPT_FILE_PATH, System.Text.Encoding.GetEncoding("shift_jis"));
|
||||
|
||||
stepInfo.Description = "なんか詳細...(笑)";
|
||||
stepInfo.InitialStepName = "なんか初期ステップ名...(笑)";
|
||||
|
||||
// ここでDTOにパース(例:セクションごとに分ける、キーと値を読み込むなど)
|
||||
// ↓仮の処理(実際はINIパーサーCLがあると別府)
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("#") ||
|
||||
line.StartsWith(";") ||
|
||||
string.IsNullOrWhiteSpace(line))
|
||||
continue;
|
||||
|
||||
// 左辺と右辺分離
|
||||
var parts = line.Split(new[] { '=' }, 2);
|
||||
|
||||
// 要素数違いは飛ばす
|
||||
if (parts.Length != 2) continue;
|
||||
|
||||
// 要素取得
|
||||
var no = parts[0].Trim();
|
||||
var text = parts[1].Trim();
|
||||
|
||||
// No重複チェック
|
||||
if (stepInfo.StepList.Any(m => m.StepNo == no))
|
||||
{
|
||||
resultMessage = $"ステップNoが重複しています。[ステップNo:{no}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// RawDTO
|
||||
var raw = new StepDTO(no, text);
|
||||
|
||||
// バリデーションと変換
|
||||
if (!ParseTryUxer.TryParse(raw, out var parsed, out string messageForMe))
|
||||
{
|
||||
resultMessage = $"ステップエラーです。[行:{line},エラー内容:{messageForMe}";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 正常:リストに追加
|
||||
stepInfo.StepList.Add(parsed);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultMessage = $"スクリプトロードに失敗しました。[エラー内容:{ex.Message}]";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using KssSmaPlaLib.AutoTest.Command.Definition;
|
||||
using KssSmaPlaLib.AutoTest.Script.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// パース済みのステップDTO(1ステップの情報)
|
||||
/// </summary>
|
||||
public class ParsedStepDTO
|
||||
{
|
||||
public string StepNo => Raw.StepNo;
|
||||
public CommandEnumUxer.Command Command { get; set; }
|
||||
public List<string> Parameters { get; set; }
|
||||
public StepDTO Raw { get; }
|
||||
|
||||
public ParsedStepDTO(StepDTO raw)
|
||||
{
|
||||
Raw = raw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// ステップDTO(1ステップの情報)
|
||||
/// </summary>
|
||||
public class StepDTO
|
||||
{
|
||||
/// <summary>
|
||||
/// ステップ番号
|
||||
/// </summary>
|
||||
public string StepNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ステップテキスト
|
||||
/// </summary>
|
||||
public string StepText { get; set; }
|
||||
|
||||
public StepDTO(string stepNo, string stepText)
|
||||
{ this.StepNo = stepNo; this.StepText = stepText; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using KssSmaPlaLib.AutoTest.Script;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// UIテストステップ全体情報
|
||||
/// </summary>
|
||||
public class StepInfoDTO
|
||||
{
|
||||
public List<ParsedStepDTO> StepList { get; set; } = new List<ParsedStepDTO>();
|
||||
public string InitialStepName { get; set; } // 最初に実行するステップ名
|
||||
public string Description { get; set; } // ステップ群の説明(任意)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Parse.Function
|
||||
{
|
||||
public class FunctionTryUxer
|
||||
{
|
||||
public static bool TryFunction(string input, out string functionName, out List<string> funcArgList,out string resultMessage)
|
||||
{
|
||||
functionName = "";
|
||||
funcArgList = new List<string>();
|
||||
resultMessage = string.Empty;
|
||||
|
||||
var match = Regex.Match(input, @"^(\w+)\((.*?)\)$");
|
||||
if (match.Success)
|
||||
{
|
||||
functionName = match.Groups[1].Value;
|
||||
var args = match.Groups[2].Value;
|
||||
if (!string.IsNullOrWhiteSpace(args))
|
||||
{
|
||||
funcArgList.AddRange(args.Split(','));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
resultMessage = $"シグネチャ形式が不正です。[シグネチャ:{input}]";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using DocumentFormat.OpenXml.Math;
|
||||
using KssSmaPlaLib.AutoTest.Command.Alias;
|
||||
using KssSmaPlaLib.AutoTest.Script.Models;
|
||||
using KssSmaPlaLib.AutoTest.Script.Parse.Function;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Parse
|
||||
{
|
||||
public static class ParseTryUxer
|
||||
{
|
||||
public static bool TryParse(StepDTO raw, out ParsedStepDTO parsed, out string resultMessage)
|
||||
{
|
||||
resultMessage = string.Empty;
|
||||
parsed = new ParsedStepDTO(raw); // Raw注入
|
||||
|
||||
// ステップNo
|
||||
if (string.IsNullOrEmpty(raw.StepNo))
|
||||
{
|
||||
resultMessage = $"UIテストステップ:ステップ番号が指定されていません。";
|
||||
return false;
|
||||
}
|
||||
|
||||
// ステップ情報:シグネチャのバリデーション
|
||||
if (!FunctionTryUxer.TryFunction(raw.StepText, out var functionName, out var argList, out var messageForMe))
|
||||
{
|
||||
resultMessage = $"UIテストステップ:ステップ情報のシグネチャの変換に失敗しました。[エラー内容:{messageForMe}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 関数(機能)名
|
||||
if (!CommandAliasUxer.TryTranslate(functionName, out var commandEnum))
|
||||
{
|
||||
resultMessage = $"UIテストステップ:ステップ情報の関数(機能)名が未登録です。[関数(機能)名:{functionName}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// コマンド(enum値)
|
||||
parsed.Command = commandEnum;
|
||||
|
||||
// パラメータ
|
||||
parsed.Parameters = argList;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using KssSmaPlaLib.AutoTest.Script.Models;
|
||||
|
||||
namespace KssSmaPlaLib.AutoTest.Script.Storage
|
||||
{
|
||||
public static class TestScriptStorageUxer
|
||||
{
|
||||
private static StepInfoDTO _stepInfo = null;
|
||||
|
||||
public static StepInfoDTO StepInfo { get { return _stepInfo; } }
|
||||
|
||||
public static void SetStepInfo(StepInfoDTO stepInfo)
|
||||
{
|
||||
_stepInfo = stepInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user