Class BeginCollectingLogsWithJavaScriptIfApplicable
- Namespace
- CSF.Screenplay.Selenium.Tasks
- Assembly
- CSF.Screenplay.Selenium.dll
Determines whether the current actor needs to use a JS technique to collect web browser console logs. If they do, executes the action which begins collecting them.
public class BeginCollectingLogsWithJavaScriptIfApplicable : IPerformable, ICanReport
- Inheritance
-
BeginCollectingLogsWithJavaScriptIfApplicable
- Implements
- Inherited Members
Remarks
When used, this action should be executed as soon as possible after the current page has completed loading. Ideally, directly after ClickAndWaitForDocumentReady and OpenUrl. This Task decides whether it is appropriate to make use of BeginCollectingLogsWithJavaScript action, invoking it if appropriate.
Note that this action/the script needs to be re-run after each traditional web page navigation/reload. However, due to the nature of SPAs, it does not need to be re-run following an SPA-style navigation. On supported browsers, there is no harm in re-running this script when it is not needed, except for the impact on performance (wasted network roundtrips).
The logic used by this task is:
- If the actor's BrowseTheWeb ability has ShouldCollectLogs set to false then the JavaScript technique will not be used.
- If the actor's BrowseTheWeb ability has the quirk HasNativeLogsSupport and the implementation of IWebDriver is not a RemoteWebDriver then the JavaScript technique will not be used.
- If the IWebDriver does not have the quirk CanGetLogsWithJavascriptWorkaround then the JavaScript technique will not be used.
- Otherwise, ShouldCollectLogs is true, the IWebDriver has the quirk CanGetLogsWithJavascriptWorkaround and does not have a better way to get the logs, then the JavaScript technique will be used.
Note that RemoteWebDriver instances cannot collect the logs natively. This is because the WebDriver remote protocol does not support this functionality. Web Drivers which support it locally cannot do so remotely. See this issue about logging being missing from the w3c WebDriver standard and the signposted minutes from this meeting for more info.
Methods
GetReportFragment(Actor, IFormatsReportFragment)
Gets a fragment of a Screenplay report, specific to the execution (performables) or gaining (abilities) of the current instance, for the specified actor.
public ReportFragment GetReportFragment(Actor actor, IFormatsReportFragment formatter)
Parameters
actorActorAn actor for whom to write the report fragment
formatterIFormatsReportFragmentA report-formatting service
Returns
- ReportFragment
A human-readable report fragment.
Examples
For a performable which clicks a button (where the button itself has been constructor-injected into
the performable instance), then a suitable return value might be a formatted string such as
{Actor name} clicks {Button}, where the two placeholders indicated by braces: {} are
substituted with the actor's Name and a string representation of
the button.
For a performable which reads the temperature from a thermometer, a suitable return value might be a
string in the format {Actor name} reads the temperature.
For an ability which allows the actor to wash dishes then a suitable return value might be a string in the
format {Actor name} is able to wash the dishes.
Remarks
Implementers should return a string which indicates that the named actor is performing (present tense)
the performable, for types which also implement a performable interface. For types which represent
abilities, the implementer should return a string which indicates that the named actor is able to do
something. In particular for abilities, to make them easily recognisable in reports, it helps to stick
to the convention {Actor name} is able to {Ability summary}.
For performables which return a value (Questions, or Tasks which behave like Questions), there is no need to include the returned value within the report fragment. The framework will include the return value in the report and will format it via a different mechanism.
Good report fragments are concise. Be aware that report fragments for Tasks (which are composed from other performables) do not need to go into detail about what they do. Users reading Screenplay reports are able to drill-down into Tasks to see what they are composed from, so if the user is curious as to what the task does, it is easy to discover. It is also strongly recommended to avoid periods (full stops) at the end of a report fragment. Whilst report fragments tend to be complete sentences, punctuation like this is distracting and reports are seldom presented as paragraphs of prose.
PerformAsAsync(ICanPerform, CancellationToken)
Performs the action(s) are represented by the current instance.
public ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)
Parameters
actorICanPerformThe actor that is performing.
cancellationTokenCancellationTokenAn optional cancellation token by which to abort the performable.
Returns
- ValueTask
A task which completes when the performable represented by the current instance is complete.
ShouldCollectLogsWithJavaScript(ICanPerform)
Gets a value indicating whether the specified actor should use the JavaScript technique to get browser logs.
public static bool ShouldCollectLogsWithJavaScript(ICanPerform actor)
Parameters
actorICanPerformThe actor
Returns
Remarks
See the remarks for this type for more information about that logic.
ShouldCollectLogsWithJavaScript(BrowseTheWeb)
Gets a value indicating whether the specified browse the web ability should use the JavaScript technique to get browser logs.
public static bool ShouldCollectLogsWithJavaScript(BrowseTheWeb browseTheWeb)
Parameters
browseTheWebBrowseTheWebThe ability
Returns
Remarks
See the remarks for this type for more information about that logic.