예제 #1
0
        public ActionResult TestAction(TestProperty prop)
        {
            //Validation
            new tawsValidate().Validate(prop);
            if (prop.validationMsg.Count != 0)
            {
                //データベースからテストケースを取得
                prop.testCaseList = new DataBaseIo().ExeReader <TestCase>("select * from test_case_t");

                return(View("Index", prop));
            }

            //var browerName = ConfigurationManager.AppSettings["BrowserName"];
            var browerName = prop.testBrowser;

            //テスト実施日時取得
            prop.testDateTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");

            //エビデンス用ディレクトリ作成
            var fileIo = new FileIo();

            prop.evidenceSavePath = fileIo.CreateEvidencesDirectory(prop);
            //テストケースファイル保存
            prop.uploadFileSavePath = fileIo.SaveTestCaseFiles(prop.testCaseFile, prop.testDateTime);

            //URL設定(configから)
            //var prop.testURL = $"{ConfigurationManager.AppSettings["Url"]}member";

            //ウィンドウ表示位置設定
            prop.positionX = 0;
            prop.positionY = 0;

            //スクリーンサイズ取得
            if (prop.testDevice == "pc")
            {
                prop.screenWidth  = Convert.ToInt32(ConfigurationManager.AppSettings["BrowerWidth"]);
                prop.screenHeight = Convert.ToInt32(ConfigurationManager.AppSettings["BrowerHeight"]);
            }
            else if (prop.testDevice == "sp_iphone")
            {
                prop.screenWidth  = Convert.ToInt32(ConfigurationManager.AppSettings["BrowerWidthiPhone"]);
                prop.screenHeight = Convert.ToInt32(ConfigurationManager.AppSettings["BrowerHeightiPhone"]);
            }
            else if (prop.testDevice == "sp_android")
            {
                prop.screenWidth  = Convert.ToInt32(ConfigurationManager.AppSettings["BrowerWidthAndroid"]);
                prop.screenHeight = Convert.ToInt32(ConfigurationManager.AppSettings["BrowerHeightAndroid"]);
            }


            //テスト実施---------------------------------------

            var excuteTest = new TestExecute();

            //Google Chromeのテスト
            if (browerName == "chrome")
            {
                //Web Driverの設定
                var option = new ChromeOptions();
                if (prop.testDevice == "sp_iphone")
                {
                    option.AddArgument($"--user-agent=\"{ ConfigurationManager.AppSettings["UserAgentiPhone"] }\"");
                }
                else if (prop.testDevice == "sp_android")
                {
                    option.AddArgument($"--user-agent=\"{ ConfigurationManager.AppSettings["UserAgentAndroid"] }\"");
                }

                excuteTest.ExeTest <ChromeDriver>(new ChromeDriver(option), prop);
            }
            //FireFoxのテスト
            else if (browerName == "firefox")
            {
                //Web Driverの設定
                var option = new FirefoxOptions();
                if (prop.testDevice == "sp_iphone")
                {
                    option.SetPreference("general.useragent.override", ConfigurationManager.AppSettings["UserAgentiPhone"]);
                }
                else if (prop.testDevice == "sp_android")
                {
                    option.SetPreference("general.useragent.override", ConfigurationManager.AppSettings["UserAgentAndroid"]);
                }
                //Proxyの設定
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["SetProxy"]))
                {
                    var fireComm = new FireFoxTestCommons();
                    option = fireComm.SetProxy(option, ConfigurationManager.AppSettings["NonProxyString"]);
                }

                excuteTest.ExeTest <FirefoxDriver>(new FirefoxDriver(option), prop);
            }
            //Edgeのテスト
            else if (browerName == "edge")
            {
                excuteTest.ExeTest <EdgeDriver>(new EdgeDriver(), prop);
            }

            prop.resultMsg = $@"{ prop.evidenceSavePath } にテスト結果が保存されました。";

            return(View("complete", prop));
        }