第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我可以使用變量在 FileStream 中設(shè)置路徑嗎?

我可以使用變量在 FileStream 中設(shè)置路徑嗎?

C#
回首憶惘然 2021-08-29 17:45:13
我在 Selenium Webdriver 中有一個(gè)使用 C# 的測(cè)試腳本,我在其中從.txt外部文件讀取數(shù)據(jù)。腳本上的路徑是固定的,表示我電腦上的一個(gè)文件夾。但是將來其他人將在其他計(jì)算機(jī)上運(yùn)行此腳本,他們將不得不直接在腳本上手動(dòng)調(diào)整路徑。是否可以將路徑設(shè)置C:\Users\...\myData.txt為一種變量,我的意思是,在腳本正文中不是永久的?這是腳本的一部分:using System;using NUnit.Framework;using OpenQA.Selenium;using OpenQA.Selenium.Chrome;using System.IO;using System.Collections;using System.Text;namespace SeleniumTests{    [TestFixture]    public class Principal    {        IWebDriver driver = null;        [SetUp]        public void SetUp()        {            ChromeOptions options = new ChromeOptions();            options.AddArguments("--disable-infobars");            options.AddArguments("start-maximized");            driver = new ChromeDriver(options);        }        public class DataTXT        {            public string example1{ get; set; }            public string example2{ get; set; }            public string example3{ get; set; }            public string example4{ get; set; }        }        public static IEnumerable DataTXT        {            get            {                string linha;                using (FileStream readFile =                new FileStream(@"C:\Users\...\myData.txt", FileMode.Open, FileAccess.Read))                {                    var reader = new StreamReader(readFile, Encoding.GetEncoding("iso-8859-1"));                    while ((line = reader.ReadLine()) != null)                    {                        var column = line.Split(';');                        yield return new DataTXT                        {                            example1 = column[0],                            example2 = column[1],                            example3 = column[2],                            example4 = column[3]                        };                    }                    reader.Close();                    readFile.Close();                }            }        }
查看完整描述

3 回答

?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊

我可能有點(diǎn)誤解你的問題,因?yàn)槲以谶@里有點(diǎn)新。但是,如果您只是想要一個(gè)不是靜態(tài)定義的并且可以由用戶更改的路徑變量;您可以使用配置文件來定義它并改為指向配置。(或 ConfigurationManager MSDN-ConfigManager


查看完整回答
反對(duì) 回復(fù) 2021-08-29
?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊

有多種方法可以做到這一點(diǎn)。

  1. 您可以在項(xiàng)目中創(chuàng)建路徑并知道它相對(duì)于 \bin 的位置。

  2. 我看到您正在使用 NUnit。NUnitTestContext.CurrentContext.TestDirectory將返回測(cè)試 dll 的路徑。如果您將 txt 文件添加到您的解決方案中并通過構(gòu)建后事件將其與 dll 一起復(fù)制,它將始終位于TestDirectory.


查看完整回答
反對(duì) 回復(fù) 2021-08-29
  • 3 回答
  • 0 關(guān)注
  • 244 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)