i am testing parallel execution of IWebDriver
vs WebClient
.
(if there's performance differance and how big it is)
before i managed to do so , i had problem with simple WebClient- Parallel invocation .
seems that it has not been executed, i did put a brake point on the AgilityPacDocExtraction
at the specific line of WebClient.DownloadString(URL)
but the program exits
instead of debug Step Into
could show yeald string .
the plan was to have single method for all actions needed to be taken,
via a "mode" selector for each action,
then using a simple foreach
that will iterate on all available Enum values
- modes
the main exeutions :
static void Main(string[] args)
{
EnumForEach<Action>(Execute);
Task.WaitAll();
}
public static void EnumForEach<Mode>(Action<Mode> Exec)
{
foreach (Mode mode in Enum.GetValues(typeof(Mode)))
{
Mode Curr = mode;
Task.Factory.StartNew(() => Exec(Curr) );
}
}
mode / Action selector
enum Action
{
Act1, Act2
}
the actual execution
static BrowsresFactory.IeEngine IeNgn = new BrowsresFactory.IeEngin();
static string
FlNm = Environment.CurrentDirectory,
URL = "",
TmpHtm ="";
static void Execute(Action Exc)
{
switch (Exc)
{
case Action.Act1:
break;
case Action.Act2:
URL = "UrlofUrChoise here...";
FlNm += "\\TempHtm.htm";
TmpHtm = IeNgn.AgilityPacDocExtraction(URL).GetElementbyId("Dv_Main").InnerHtml;
File.WriteAllText(FlNm, TmpHtm);
break;
}
}
class that hold WebClient
and IWebDriver
(by selenium) not included here so it will not take some more room in this post and allso not relevent for now.
class BrowsresFactory
{
public class IeEngine
{
private WebClient WC = new WebClient();
private string tmpExtractedPageValue = "";
private HtmlAgilityPack.HtmlDocument retAglPacHtmDoc = new HtmlAgilityPack.HtmlDocument();
public HtmlAgilityPack.HtmlDocument AgilityPacDocExtraction(string URL)
{
WC.Encoding = Encoding.GetEncoding("UTF-8");
tmpExtractedPageValue = WC.DownloadString(URL); //<--- tried to break here
retAglPacHtmDoc.LoadHtml(tmpExtractedPageValue);
return retAglPacHtmDoc;
}
}
}
the problem is that i cant see any content in the file that was supposed to be alterd via value extracted from the WebClient , plus when in debug mode i couldn't step into the line commented in above code. what am i doing Wrong here ?
The function
Download(url, htmlDictionary)
is not defined in the above code, one possible version is:... the above codes seems a copy from another Stack Overflow post. For reference see Retrieve a string containing html Document source using Task parallel
I have managed to solve the issue by making a use of
WebClient
which I think requires less resources thanWebDriver
and if thats true it also means that takes less time.This is the code :