// Attribute /// <summary> /// Asserts that the element has the specified attribute. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="name">The attribute name</param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> public static ElementHandle ShouldHaveAttribute(this ElementHandle elementHandle, string name, string because = null) { elementHandle.ShouldHaveAttributeAsync(name, because).Result(); return(elementHandle); }
/// <summary> /// Asserts that the element does not have focus. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> /// <remarks><![CDATA[Elements: <button>, <input>, <keygen>, <select>, <textarea>]]></remarks> public static ElementHandle ShouldNotHaveFocus(this ElementHandle elementHandle, string because = null) { elementHandle.ShouldNotHaveFocusAsync(because).Result(); return(elementHandle); }
/// <summary> /// Asserts that the element does not have the specified value. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="value">The value</param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> /// <remarks><![CDATA[Elements: <button>, <option>, <input>, <li>, <meter>, <progress>, <param>]]></remarks> public static ElementHandle ShouldNotHaveValue(this ElementHandle elementHandle, string value, string because = null) { elementHandle.ShouldNotHaveValueAsync(value, because).Result(); return(elementHandle); }
public static async Task <string> GetAttributeAsync(this ElementHandle element, string name, Page page) { return(await page.EvaluateFunctionAsync <string>($"(el) => el.getAttribute(\"{name}\")", element)); }
/// <summary> /// Asserts that the element is not required. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> /// <remarks><![CDATA[Elements: <input>, <select>, <textarea>]]></remarks> public static ElementHandle ShouldNotBeRequired(this ElementHandle elementHandle, string because = null) { elementHandle.ShouldNotBeRequiredAsync(because).Result(); return(elementHandle); }
public static void ShouldBeVisible(ElementHandle handle, string message) { Exception("Should be visible, but is not.", message); }
public static void ShouldNotBeChecked(ElementHandle handle, string message) { Exception("Should not be checked, but is.", message); }
public Task SetInputFilesAsync(ElementHandle handle, IEnumerable <FilePayload> files) => handle.EvaluateHandleAsync(Dom.SetFileInputFunction, files);
private async Task AssertBodyAsync(ElementHandle body, string text) { var bodyText = await body.EvaluateFunctionAsync <string>("x=>x.innerText"); Assert.Equal(text, bodyText?.Trim()); }
// Total CPU [unit, %]: 676 private async Task <List <VkBrwUserWallPost> > GetPostsViaDesktopPuppeteer() { List <VkBrwUserWallPost> result = new List <VkBrwUserWallPost>(); string vkMessageHeaderInformationLocalized = (Vkontakte.Language == BrowsingLanguage.RU) ? "Информация" : "Information"; string vkMessageHeaderErrorLocalized = (Vkontakte.Language == BrowsingLanguage.RU) ? "Ошибка" : "Error"; string hiddenDescriptionLocalized = (Vkontakte.Language == BrowsingLanguage.RU) ? "Пользователь предпочёл скрыть эту страницу." : "This user has chosen to hide their page."; ElementHandle vkMessageElement = await _userPage.QuerySelectorAsync("div.message_page.page_block"); if (vkMessageElement != null) { ElementHandle vkMessageHeaderElement = await vkMessageElement.QuerySelectorAsync("div.message_page_title"); if (vkMessageHeaderElement != null) { string vkMessageHeaderText = await vkMessageHeaderElement.EvaluateFunctionAsync <string>("('div', div => div.innerText)"); if (vkMessageHeaderText == vkMessageHeaderInformationLocalized) { Vkontakte.NonExistingProfiles += 1; } else if (vkMessageHeaderText == vkMessageHeaderErrorLocalized) { ElementHandle vkMessageBodyElement = await vkMessageElement.QuerySelectorAsync("div.message_page_body"); if (vkMessageBodyElement != null) { string vkMessageBodyText = await vkMessageBodyElement.EvaluateFunctionAsync <string>("('div', div => div.innerText)"); string vkMessageBodyDescription = vkMessageBodyText.Split('\n')[0]; if (vkMessageBodyDescription == hiddenDescriptionLocalized) { HiddenProfile = true; Vkontakte.NonPublicProfiles += 1; } else// if (mmm == "Вы попытались загрузить более одной однотипной страницы в секунду.") { Console.WriteLine(ProfileLink + " has the following vk message: " + vkMessageBodyDescription); } } else { Console.WriteLine(ProfileLink + " doesn't contain vk message body."); } } else { Console.WriteLine(ProfileLink + " error header text is " + vkMessageHeaderText); } } } else { ElementHandle[] wallPostElements = await _userPage.QuerySelectorAllAsync("div._post_content"); if (wallPostElements != null && wallPostElements.Length > 0) { foreach (ElementHandle postElement in wallPostElements) { VkBrwUserWallPost post = new VkBrwUserWallPost(); ElementHandle dateElement = await postElement.QuerySelectorAsync("span.rel_date"); if (dateElement != null) { string postDateRaw = await dateElement.EvaluateFunctionAsync <string>("('span', span => span.innerText)"); DateTime postDate = Vkontakte.Language == BrowsingLanguage.RU ? ConvertVkWallPostRusDate(postDateRaw) : ConvertVkWallPostEngDate(postDateRaw); if (postDate != DateTime.MinValue) { post.Date = postDate; } } ElementHandle wallPostTextElement = await postElement.QuerySelectorAsync("div.wall_text"); if (wallPostTextElement != null) { post.Repost = (await wallPostTextElement.QuerySelectorAsync("div.copy_quote") != null); ElementHandle postT = await wallPostTextElement.QuerySelectorAsync("div.wall_post_text"); if (postT != null) { post.Text = await postT.EvaluateFunctionAsync <string>("'div', div => div.innerText"); } } result.Add(post); post.User = this; WallPosts.Add(post); } Vkontakte.CollectedProfiles += 1; } else { Vkontakte.EmptyWallProfiles += 1; } } return(result); }
internal void Initialize(Page page, ElementHandle element) { Page = page; Element = element; }
private async Task <List <VkBrwUserWallPost> > GetPostsViaMobilePuppeteer() { List <VkBrwUserWallPost> result = new List <VkBrwUserWallPost>(); string hiddenDescriptionLocalized = (Vkontakte.Language == BrowsingLanguage.RU) ? "Страница доступна только авторизованным пользователям." : "You have to log in to view this page."; string emptyWallDescriptionLocalized = (Vkontakte.Language == BrowsingLanguage.RU) ? "На стене пока нет ни одной записи." : "This wall is empty."; ElementHandle vkMessageElement = await _userPage.QuerySelectorAsync("div.service_msg.service_msg_null"); if (vkMessageElement != null) { //"Страница удалена либо ещё не создана." // string vkMessageText = await vkMessageElement.EvaluateFunctionAsync <string>("('div', div => div.innerText)"); if (vkMessageText == hiddenDescriptionLocalized) { Vkontakte.NonPublicProfiles += 1; } else if (vkMessageText == emptyWallDescriptionLocalized) { Vkontakte.EmptyWallProfiles += 1; } else { Vkontakte.NonExistingProfiles += 1; } } else { ElementHandle[] wallPostElements = await _userPage.QuerySelectorAllAsync("div.wall_item"); if (wallPostElements.Length > 0) { foreach (ElementHandle postElement in wallPostElements) { VkBrwUserWallPost post = new VkBrwUserWallPost(); ElementHandle dateElement = await postElement.QuerySelectorAsync("a.wi_date"); if (dateElement != null) { string postDateRaw = await dateElement.EvaluateFunctionAsync <string>("('a', a => a.innerText)"); DateTime postDate = Vkontakte.Language == BrowsingLanguage.RU ? ConvertVkWallPostRusDate(postDateRaw) : ConvertVkWallPostEngDate(postDateRaw); if (postDate != DateTime.MinValue) { post.Date = postDate; } } ElementHandle wallPostTextElement = await postElement.QuerySelectorAsync("div.pi_text"); if (wallPostTextElement != null) { post.Text = await wallPostTextElement.EvaluateFunctionAsync <string>("'span', span => span.innerText"); } string repostValue = await postElement.EvaluateFunctionAsync <string>("('div', div => { return div.getAttribute('data-copy'); })"); post.Repost = !string.IsNullOrEmpty(repostValue); result.Add(post); post.User = this; WallPosts.Add(post); } Vkontakte.CollectedProfiles += 1; } else { Vkontakte.NonPublicProfiles += 1; } } return(result); }
protected override async Task SetUp() { await Page.SetContentAsync(Fake.Html); _elementHandle = await Page.QuerySelectorAsync("html"); }
public static bool ExecuteElementDraggedAndDropped(ElementHandle draggedElementHandle, ElementHandle newParentdElementHandle, int dropIndex, string consoleId, bool isCopy) { FlowControllerServicesContainer flowServicesContainer = new FlowControllerServicesContainer(); flowServicesContainer.AddService(new ManagementConsoleMessageService(consoleId)); flowServicesContainer.AddService(new ElementDataExchangeService(draggedElementHandle.ProviderName)); flowServicesContainer.AddService(new ActionExecutionService(draggedElementHandle.ProviderName, consoleId)); return(ElementFacade.ExecuteElementDraggedAndDropped(draggedElementHandle, newParentdElementHandle, dropIndex, isCopy, flowServicesContainer)); }
public static void ShouldNotHaveClass(ElementHandle handle, string message) { Exception("Should not have class, but did.", message); }
/// <summary> /// Asserts that the element does not have the specified content. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="regex">A regular expression to test against <c>element.textContent</c></param> /// <param name="flags">A set of flags for the regular expression</param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> /// <seealso href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp"/> public static ElementHandle ShouldNotHaveContent(this ElementHandle elementHandle, string regex, string flags = "", string because = null) { elementHandle.ShouldNotHaveContentAsync(regex, flags, because).Result(); return(elementHandle); }
public static void ShouldExist(ElementHandle handle, string message) { Exception("Should exist, but did not.", message); }
/// <summary> /// Asserts that the element does not have the specified class. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="className">The class name</param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> public static ElementHandle ShouldNotHaveClass(this ElementHandle elementHandle, string className, string because = null) { elementHandle.ShouldNotHaveClassAsync(className, because).Result(); return(elementHandle); }
public static void ShouldBeHidden(ElementHandle handle, string message) { Exception("Should be hidden, but is not.", message); }
// ReadOnly /// <summary> /// Asserts that the element is read-only. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>The <see cref="ElementHandle"/> for method chaining</returns> /// <remarks><![CDATA[Elements: <input>, <textarea>]]></remarks> public static ElementHandle ShouldBeReadOnly(this ElementHandle elementHandle, string because = null) { elementHandle.ShouldBeReadOnlyAsync(because).Result(); return(elementHandle); }
public static void ShouldBeEnabled(ElementHandle handle, string message) { Exception("Should be enabled, but is not.", message); }
private static Element CreateResourceElement(string resourceSet, string label, ElementHandle elementHandle) { if (String.IsNullOrEmpty(resourceSet)) { var dragAndDropInfo = new ElementDragAndDropInfo(typeof(IResourceKey)); dragAndDropInfo.AddDropType(typeof(NamespaceFolderEntityToken)); dragAndDropInfo.SupportsIndexedPosition = false; return(new Element(elementHandle, dragAndDropInfo) { VisualData = new ElementVisualizedData { Label = label, ToolTip = label, HasChildren = false, Icon = ResourceHandle.BuildIconFromDefaultProvider("localization-element-closed-root"), OpenedIcon = ResourceHandle.BuildIconFromDefaultProvider("localization-element-opened-root") } }); } return(new Element(elementHandle) { VisualData = new ElementVisualizedData { Label = label, ToolTip = label, HasChildren = false, Icon = ResourceHandle.BuildIconFromDefaultProvider("localization-element-closed-root"), OpenedIcon = ResourceHandle.BuildIconFromDefaultProvider("localization-element-opened-root") } }); }