/*
 * Copyright @ 2018 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jitsi.meet.test.pageobjects.web;

import org.jitsi.meet.test.util.*;
import org.jitsi.meet.test.web.WebParticipant;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;

import java.util.*;

import static org.testng.AssertJUnit.fail;

/**
 * Represents the chat panel in a particular {@link WebParticipant}.
 *
 * @author Boris Grozev
 */
public class ChatPanel
{
    /**
     * The participant.
     */
    private final WebParticipant participant;

    /**
     * Initializes a new {@link ChatPanel} instance.
     * @param participant the participant for this {@link ChatPanel}.
     */
    public ChatPanel(WebParticipant participant)
    {
        this.participant = Objects.requireNonNull(participant, "participant");
    }

    /**
     * @return {@code true} if the chat panel is open/visible and {@code false}
     * otherwise.
     */
    public boolean isOpen()
    {
        Object o = participant.executeScript("return APP.UI.isChatVisible();");
        return o != null && Boolean.parseBoolean(o.toString());
    }

    /**
     * Clicks on the "chat" toolbar button which opens or closes the chat panel.
     */
    public void clickToolbarButton()
    {
        MeetUIUtils.clickOnButton(
            participant.getDriver(),
            "toolbar_button_chat",
            true);
    }

    /**
     * Presses the "chat" keyboard shortcut which opens or closes the chat
     * panel.
     */
    public void pressShortcut()
    {
        participant.pressShortcut('c');
    }

    /**
     * Fails if the chat panel doesn't reach the open state withing a timeout.
     */
    public void assertOpen()
    {
        waitForOpenedOrClosed(true /* open */);
    }

    /**
     * Fails if the chat panel doesn't reach the closed state withing a timeout.
     */
    public void assertClosed()
    {
        waitForOpenedOrClosed(false /* closed */);
    }

    /**
     * Will wait until chat panel is opened or closed. If the opened/closed
     * condition is not met after given timeout it will fail the test.
     *
     * @param open - {@code true} to wait until the panel is open, and
     * {@code false} to wait until it is closed.
     */
    private void waitForOpenedOrClosed(boolean open)
    {
        participant.waitForCondition(
                () -> open == isOpen(),
                2,
                String.format(
                        "The chat panel was expected to be %s.",
                        open ? "open" : "closed"));
    }
}

@@ -1517,141 +1517,125 @@
     
-Object o = participant.executeScript(%22return APP.UI.isChatVisible();%22);%0A        return o != null && Boolean.parseBoolean(o.toString()
+return this.participant.getDriver()%0A            .findElement(By.id(%22sideToolbarContainer%22))%0A            .isDisplayed(
 );%0A 

change visibility check to use webdriver instead of JS (#208)