1 package net.avcompris.guixer.core;
2
3 import java.io.IOException;
4
5 import javax.annotation.Nullable;
6
7 import org.openqa.selenium.ElementNotInteractableException;
8 import org.openqa.selenium.ElementNotVisibleException;
9 import org.openqa.selenium.InvalidSelectorException;
10 import org.openqa.selenium.NoSuchElementException;
11 import org.openqa.selenium.TimeoutException;
12 import org.openqa.selenium.WebDriverException;
13
14 final class CommandDumperLoggerImpl extends AbstractCommandLoggerImpl {
15
16 public CommandDumperLoggerImpl(
17 final Command delegate,
18 final Context context,
19 @Nullable final String actionShortDescription
20 ) throws IOException {
21
22 super(delegate, context, context.getDumperLogger(), actionShortDescription);
23 }
24
25 public CommandDumperLoggerImpl(
26 final Command delegate,
27 final Context context
28 ) throws IOException {
29
30 this(delegate, context, null);
31 }
32
33 @Override
34 protected void handleError(final WebDriverException e) throws IOException {
35
36 logger.error(e);
37
38 final String label;
39
40 if (e instanceof TimeoutException) {
41
42 label = "TIMEOUT_ERROR";
43
44 } else if (e instanceof InvalidSelectorException) {
45
46 label = "INVALID_SELECTOR_ERROR";
47
48 } else if (e instanceof NoSuchElementException) {
49
50 label = "NO_SUCH_ELEMENT_ERROR";
51
52 } else if (e instanceof ElementNotVisibleException) {
53
54 label = "ELEMENT_NOT_VISBILE_ERROR";
55
56 } else if (e instanceof ElementNotInteractableException) {
57
58 label = "ELEMENT_NOT_INTERACTABLE_ERROR";
59
60 } else {
61
62 label = "ERROR";
63 }
64
65 takeScreenshot(label);
66
67 throw e;
68 }
69 }