понедельник, 18 декабря 2017 г.

IT - AQA: Selenium+javascript: node.js - wotk with wait and assertion (updated)



Examples:
1)  Wait until element will shown:
const until = selenium.until;
driver.wait(until.elementLocated(locators.detailsGenresDropDown), 5000);

2) implicitlyWait() in javascript selenium bindings accepts a single argument - a timeout in milliseconds:
driver.manage().timeouts().implicitlyWait(20000);

3) page is loaded:
java:  driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
js: driver.manage().timeouts().pageLoadTimeout(10);

4) The code above makes browser wait for 5 seconds after clicking the button (+1).
driver.findElement(webdriver.By.name('btnCalculate')).click().then(function() {
    driver.sleep(5000);
});

If using webdriverJs (node.js),

5) What's the equivalent of Java's Thread.sleep() in JavaScript? (+1)
The simple answer is that there is no such function.
The closest thing you have is:
var millisecondsToWait = 500;
setTimeout(function() {
    // Whatever you want to do after the wait
}, millisecondsToWait);
Note that you especially don't want to busy-wait (e.g. in a spin loop), since your browser is almost certainly executing your JavaScript in a single-threaded environment.
Here are a couple of other SO questions that deal with threads in JavaScript:
And this question may also be helpful:
6) Just sleep for several seconds:// Page has been loaded, now go to sleep for a few seconds.
driver.sleep(3000); 
 

Assertion

Examples:

1)    client.getTitle().then(function(title) {
        assert.ok(title.indexOf('test — Яндекс: нашлось') > -1, 'Ничего не нашлось :(');
    });


Links
WebDriver: Advanced Usage - Explicit and Implicit Waits
Документация по Selenium.
Документация по WebDriver.js;
Черновик спецификации WebDriver API;
Webdriver selenium js docs

воскресенье, 3 декабря 2017 г.

AQA: Selenium: Javascript collection of tricks

Collection of knowledge about selenium + js 



Console на полную: console, log, info, warn, assert, trace (link1)
Clipboard copy and paste (link1)

Insert data in textarea:
- how to send a page source to a text area (link question, link with java examples). Used code:
String page=driver.getPageSource();
WebElement e=driver.findElement(By.xpath("textarea xpath");
e.sendKeys(page);
-  Using sendKeys( ) command for entering multiple lines of text into a Text Area field (link). Used code:
const text2 = "My super long text \n string to be typed into \n textarea element";
\b - backspace
\t -  tab
\n - newline
\f -  form feed
\r - carriage return
\" - double quote
\' -  single quote
\\ - backslash
- Using clipboard. (link)
Clipboard.SetText(trgt);
myTextArea.SendKeys(OpenQA.Selenium.Keys.Control + "v");
- Learn how to upload a file using Selenium Webdriver with Sauce Labs’ guide.(link1, link2)
- C помощью Selenium Webdriver ввести текст в frame редакторa tinymce (link1):
driver.switchTo().frame("news_globalize_translations_attributes_ru_content_ifr");
driver.findElement(By.id("tinymce")).sendKeys("Text");
driver.switchTo().defaultContent();

JavaScriptExecutor in Selenium WebDriver With Examples (original link)

JavaScriptExecutor in Selenium WebDriver:
In general, we do click on an element using click() method in Selenium.
For example:
Sometimes web controls don’t react well against selenium commands and we may face issues with the above statement (click()). To overcome such kind of situation, we use JavaScriptExecutor interface.
It provides mechanism to execute Javascript through Selenium driver. It provides “executescript” & “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window.
There is no need to write separate script to execute JavaScript within the browser using Selenium WebDriver script. Just use predefined interface named ‘Java Script Executor’. We need to import the below package in the script.
Package:
Syntax:
Script – The JavaScript to execute
Arguments –
The arguments to the script(Optional). May be empty.
Returns –
One of Boolean, Long, String, List, WebElement, or null.
Let’s see some scenarios we could handle using this Interface:
  • To type Text in Selenium WebDriver without using sendKeys() method
  • To click a Button in Selenium WebDriver using JavaScript
  • To handle Checkbox
  • To generate Alert Pop window in selenium
  • To refresh browser window using Javascript
  • To get innertext of the entire webpage in Selenium
  • To get the Title of our webpage
  • To get the domain
  • To get the URL of a webpage
  • To perform Scroll on application using  Selenium
See Also: How To Scroll Web Page Down Or UP Using Selenium WebDriver
  • To click on a SubMenu which is only visible on mouse hover on Menu
  • To navigate to different page using Javascript
  • To find hidden element in selenium using JavaScriptExecutor
Below program will guide you to handle some of the scenarios we do use in while writing scripts.
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 


вторник, 24 октября 2017 г.

AQA: javascript: node.js(main) - SetUp environment for testing

1) Take Browser with stable functionality: Chrome, FireFox
2) 
npm install selenium-webdriver
 
To solve warning message like:
npm WARN saveError ENOENT: no such file or directory, open 'S:\temp\package.json'


Use:
1) Instruction: 
You can resolve that issue by following methods:
  1. Ensure dependencies described correctly on package.json
  2. Just type npm install and hit Enter.
  3. Check issue still exists. and If issue not resolved, continue these methods.
  4. type npm cache clean and hit Enter
  5. type sudo npm install -g npm and hit Enter.
  6. Retry npm install and hit Enter.
if issue not resolved even tried these methods, Please reply with your Node.js version, NPM version, Operating System, and package.json which is using.

2) Instruction: 
 It seems trying npm install in uninitialized npm package directory.
you should initialize package with npm init.

Use your Command Line and navigate to the root folder of your project and enter
$ npm init
This command will ask you some questions to generate a package.jsonfile in your project route that describes all the dependencies of your project. This file will be updated when adding further dependencies during the development process, for example when you set up your build system.
name: (project-name) project-name
version: (0.0.0) 0.0.1
description: The Project Description
entry point: //leave empty
test command: //leave empty
git repository: //the repositories url
keywords: //leave empty
author: // your name
license: N/A
After you've finished the process of initializing your project using the Node Package Manager, node.js created a package.jsonfile in your project's root direcotry similar to this one:
{
  "name": "project-name",
  "version": "0.0.1",
  "description": "Project Description",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "the repositories url"
  },
  "author": "your name",
  "license": "N/A"
}

Link:
Getting started with Selenium WebDriver for node.js - very good integration test
How to write reliable browser tests using Selenium and Node.js - full using 
Moving to fullstack end-to-end test automation with Node.js part 1 - Selenium Webdriver 
Selenium WebDriver is a powerful tool that plays well across different platforms
- Understanding asynchronous testing  
- Writing tests with Jasmine
Setting up your own test automation environment (+1) - a lot of tricks (multiple browsers, installation, environment variable, use URL or local document, specific keys, wait till complete, Running remote tests, mocha and chai, work with sessions,  own remote server, Integrating selenium with CI tools (also      Introduction to cross browser testing     Strategies for carrying out testing     Handling common HTML and CSS problems     Handling common JavaScript problems     Handling common accessibility problems     Implementing feature detection     Introduction to automated testing     Setting up your own test automation environment   )
driver.get('file:///Users/chrismills/git/learning-area/tools-testing/cross-browser-testing/accessibility/fake-div-buttons.html');
 

SEO: Эксперимент: как Яндекс и Google учитывают ключевые слова в URL

Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Дата пу...