diff --git a/configure.ac b/configure.ac
index db70f469bfbd..e6f17535931e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12589,18 +12652,28 @@ if ! test "$ENABLE_GTK3" = TRUE; then
     enable_atspi_tests=no
 fi
 if ! test "$enable_atspi_tests" = no; then
+    AC_PATH_PROGS([XWFB_RUN], [xwfb-run], no) # xwayland variant
     AC_PATH_PROGS([XVFB_RUN], [xvfb-run], no)
-    if ! test "$XVFB_RUN" = no; then
-        dnl make sure the found xvfb-run actually works
-        AC_MSG_CHECKING([whether $XVFB_RUN works...])
-        if $XVFB_RUN --auto-servernum true >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
+    if ! test "$XWFB_RUN" = no; then
+	    	xvfb_run_cmd = $XWFB_RUN
+		xvfb_run_cmd_arg = -a
+    else if ! test "$XVFB_RUN" = no; then
+	    	xvfb_run_cmd = $XVFB_RUN
+		xvfb_run_cmd_arg = -a true
+    else
+	    	xvfb_run_cmd=no
+    fi
+    if ! test "$xvfb_run_cmd" != "no"; then
+        dnl make sure the found x{w,v}fb-run actually works
+        AC_MSG_CHECKING([whether $xvfb_run_cmd works...])
+        if $xvfb_run_cmd $xvfb_run_cmd_arg true >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
             AC_MSG_RESULT([yes])
         else
             AC_MSG_RESULT([no])
-            XVFB_RUN=no
         fi
+	xvfb_run_cmd=no
     fi
-    if test "$XVFB_RUN" = no; then
+    if test "$xvfb_run_cmd" = no; then
         if test "$enable_atspi_tests" = yes; then
             AC_MSG_ERROR([xvfb-run required by --enable-atspi-tests not found])
         fi
