use crate::page::locator::{AriaRole, Locator, RoleLocatorBuilder, Selector};
use crate::page::{DEFAULT_TEST_ID_ATTRIBUTE, Page};
impl Page {
pub fn locator(&self, selector: impl Into<String>) -> Locator<'_> {
Locator::new(self, Selector::Css(selector.into()))
}
pub fn get_by_text(&self, text: impl Into<String>) -> Locator<'_> {
Locator::new(
self,
Selector::Text {
text: text.into(),
exact: false,
},
)
}
pub fn get_by_text_exact(&self, text: impl Into<String>) -> Locator<'_> {
Locator::new(
self,
Selector::Text {
text: text.into(),
exact: true,
},
)
}
pub fn get_by_role(&self, role: AriaRole) -> RoleLocatorBuilder<'_> {
RoleLocatorBuilder::new(self, role)
}
pub fn get_by_test_id(&self, test_id: impl Into<String>) -> Locator<'_> {
let id = test_id.into();
if self.test_id_attribute == DEFAULT_TEST_ID_ATTRIBUTE {
Locator::new(self, Selector::TestId(id))
} else {
Locator::new(
self,
Selector::TestIdCustom {
id,
attribute: self.test_id_attribute.clone(),
},
)
}
}
pub fn test_id_attribute(&self) -> &str {
&self.test_id_attribute
}
pub fn set_test_id_attribute(&mut self, attribute: impl Into<String>) {
self.test_id_attribute = attribute.into();
}
pub fn get_by_label(&self, label: impl Into<String>) -> Locator<'_> {
Locator::new(self, Selector::Label(label.into()))
}
pub fn get_by_placeholder(&self, placeholder: impl Into<String>) -> Locator<'_> {
Locator::new(self, Selector::Placeholder(placeholder.into()))
}
pub fn get_by_alt_text(&self, alt: impl Into<String>) -> Locator<'_> {
Locator::new(
self,
Selector::AltText {
text: alt.into(),
exact: false,
},
)
}
pub fn get_by_alt_text_exact(&self, alt: impl Into<String>) -> Locator<'_> {
Locator::new(
self,
Selector::AltText {
text: alt.into(),
exact: true,
},
)
}
pub fn get_by_title(&self, title: impl Into<String>) -> Locator<'_> {
Locator::new(
self,
Selector::Title {
text: title.into(),
exact: false,
},
)
}
pub fn get_by_title_exact(&self, title: impl Into<String>) -> Locator<'_> {
Locator::new(
self,
Selector::Title {
text: title.into(),
exact: true,
},
)
}
}