在Espresso中测试包含HTML标签的字符串,可以通过以下步骤实现:
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.4.0'
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.web.assertion.WebViewAssertions;
import androidx.test.espresso.web.matcher.DomMatchers;
import androidx.test.espresso.web.sugar.Web;
import androidx.test.espresso.web.webdriver.DriverAtoms;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.espresso.web.webdriver.WebDriverAssertions;
import androidx.test.espresso.web.webdriver.WebDriverAtomScripts;
import androidx.test.espresso.web.webdriver.WebDriverWebActions;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.web.assertion.WebViewAssertions;
import androidx.test.espresso.web.matcher.DomMatchers;
import androidx.test.espresso.web.sugar.Web;
import static androidx.test.espresso.web.webdriver.DriverAtoms.*;
import static androidx.test.espresso.web.webdriver.Locator.*;
import static androidx.test.espresso.web.webdriver.WebDriverAssertions.*;
import static androidx.test.espresso.web.webdriver.WebDriverAtomScripts.*;
import static androidx.test.espresso.web.webdriver.WebDriverWebActions.*;
@RunWith(AndroidJUnit4.class)
public class HtmlStringTest {
@Test
public void testHtmlString() {
String htmlString = "<p>This is a <strong>bold</strong> text.</p>";
Espresso.onView(withId(R.id.webview))
.perform(webClick())
.perform(webKeys(htmlString))
.check(webMatches(getText(), DomMatchers.containsText("bold")));
}
}
这样,就可以在Espresso中测试包含HTML标签的字符串了。在测试方法中,我们使用Espresso的web操作来模拟在WebView中输入HTML字符串,并使用DomMatchers来验证是否包含指定的文本。
领取专属 10元无门槛券
手把手带您无忧上云