我在Selenium Web驅動程序中編寫測試用例,我想將結果輸出到日誌文件。測試用例應該在文本文件中按行編號。編號已經實現,但附加測試用例是我無法實現的。問題是for循環,我想追加通過引用傳遞的變量組合。這些變量將成爲測試用例。如果需要更多解釋,請告訴我。將「由參考變量調用」追加到文本文件中
問題是,連接定義的變量只能爲所有值附加一個值。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication5
{
class Class1
{
public static int counter;
public static String[] test = {"1", "2" };
public static String[] test1 = { "a", "b" };
public static void Main(String[] args)
{
new Class1().testing2();
}
public String testing(String ab, String cd)
{
//Count the number of times the method is called
++counter;
//Write it to a text file
File.WriteAllText(@"C:\Users\ken4ward\Desktop\Tidy\WriteLines.txt", counter.ToString());
//Read from that text file
String Readfiles = File.ReadAllText(@"C:\Users\ken4ward\Desktop\Tidy\WriteLines.txt");
//Convert to integer
Int32 myInt = Int32.Parse(Readfiles);
//Store in array variable
String[] start = new String[myInt];
//iterate through
for (int i = 0; i < myInt; ++i)
{
**start[i] = (i + 1).ToString() +ab +cd;**
}
//Write into another text file on new lines
File.WriteAllLines(@"C:\Users\ken4ward\Desktop\Tidy\Writing.txt", start);
String gb = ab; String th = cd; String you = ab + cd;
return you;
}
public void testing2()
{
foreach(var item in Class1.test)
{
foreach (var item1 in Class1.test1)
{
String test = testing(item, item1);
Console.WriteLine(test);
Console.ReadLine();
}
}
}
}
}
當我跑了它這是在文本文件中的輸出:
1 2b
2 2b
3 2b
4 2b
什麼,我想在文本文件輸出爲:
1 1a
2 1b
3 2a
4 2b
你的問題不清楚。你能展示什麼方法輸出,你真的想要它輸出? –
謝謝。我編輯它添加我期待的輸出。 – kehinde
這行代表什麼意思?** start [i] =(i + 1).ToString()+ ab + cd; **'?你的意思是'開始[i] =(i + 1).ToString()+ ab + cd;'? – J3soon