Automating registration flow using Selenium Web driver - selenium

I am new to web driver. I am supposed to test a registration form using selenium2. I am being told to use functional testing to test the form. I have to make tests like(enter username, password, confirm password and click on terms and conditions and only then the create account button gets enabled.I have to enter invalid username, password less than the specified length and for each test I have to assert if the create account button gets enabled.) Checked about functional testing but couldn't get the right information for my issue.
Appreciate help on this
Thanks
Java Beginner.

The fields which are present in the website are called as WebElements.
In Selenium, you can find the element and write string by using the code:
WebElement username = driver.findElement(By.id("your field ID"));
username.sendKeys("your value");
You can do the same thing for the password. Try using dataProvider concept in TestNG to pass different types of values to the same function.

For simple tests try Selenium IDE. Then select "Options -> Clipboard Format -> Java/Junit 4/Webdriver". Copy all the html code and paste in the framework you're using. It will allow you to understand basic workflow and syntax of the application.

Related

Using Selenium IDE for a test-case which includes backend call?

I add a new category in the admin panel and want to ensure that the category is available in the dropdown on the user's part of the website. Recorded test in the Selenium IDE works fine. But the thing is, the task that I execute is of course not a pure frontend thing - the category is saved in the database and is loaded from it to show it to the user. So if something goes wrong on the database-side, the test will fail.
My question is: is it bad practice to do such tests that depend on backend-behavior ? Should I go for Selenium Webdriver ?
If you use Selenium Webdriver, your test will not change in a main thing. It still will check database side. Selenium Webdriver is just anouther tool for testing that is more flexible and allows to make more complex test then in Selenium IDE.
I don't think that it is bad practice, because it is just one of the tests that chould be executed to enshure you that this part of your project works correctly. In this case I would check back-end part(get all categories from DB or admin's panel and check that there is no extra or missing ones) and than check user's panel(all categories are the same as set in DB and admin's panel).

How does this website detect remote control with selenium and chromedriver?

I’m trying to screen scrape my own credit card information from the Discover website using selenium and chromedriver. In response it returns the error:
Your account cannot currently be accessed.
Outdated browsers can expose your computer to security risks. To get
the best experience on Discover.com, you may need to update your
browser to the latest version and try again.
Interestingly, if I write a script to open a headed browser and type in some random account and password, it works normally. But if the script first touches the web page and then I type, I get the above error message. The script that works is:
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.execute_script('window.location.href = "https://portal.discover.com/customersvcs/universalLogin/ac_main";')
It fails if I append these lines to the script and type after the sleep finishes:
time.sleep(5)
driver.find_element_by_id('userid-content').click()
I’ve tried other ways to enter data into the page, such as send_keys and executing Javascript to modify the page and they all fail the same way.
How can the website detect the remote control? Is there a way to circumvent it?
I have tried with your concept and your code block and have realized Yes portal.discover.com is able to detect Automated Logins.
One aspect is that filling up the User ID and Password field and even clicking Submit button is still achievable. Here is the relevant code block :
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.execute_script('window.location.href = "https://portal.discover.com/customersvcs/universalLogin/ac_main";')
time.sleep(5)
driver.find_element_by_css_selector("input#userid-content").send_keys("Harold")
driver.find_element_by_css_selector("input#password-content").send_keys("Harold")
# driver.find_element_by_css_selector("form#login-form-content input#log-in-button").click()
Snapshot with filledup User ID and Password field :
But one you click on the Submit button, the loginForm is validated through a JavaScript function validateForm(this); invoked at onsubmit event.
Amazingly, even before the User Credentials are validated the website seems to be detecting the Automated Login Process and sends back :
Your account cannot currently be accessed.
Outdated browsers can expose your computer to security risks. To get the best experience on Discover.com, you may need to update your browser to the latest version and try again.
For questions, please contact us at 1-800-347-7769. We're always available 24 hours a day, 7 days a week.
Snapshot of the error :
Reference
You can find a couple of detailed discussions in:
Can a website detect when you are using selenium with chromedriver?

Command for logging into an account using Selenium IDE

I'm trying to test whether logging into an account is successful using Selenium IDE.
Is there a particular command that I can use in Selenium IDE to test whether I can successfully log into my account on facebook for instance? Any help would be very much appreciated. Thanks!
There isn't a single command to fill out an entire form. However, the type command can be used for each field:
Replace username with whatever the actual ID of each field is (which can be seen by right-clicking the page and viewing the page source). You can use many other HTML attributes in this manner, such as name and class; have a look at the documentation for more examples.
Then, simply repeat this procedure for each field you wish to fill in. To actually log in, you'll need the click command targeting the Login button. This is used the same way as the type command above, but doesn't need anything in the Value field.
Once you're actually in, you can check if it was successful by using the assertText command, targeting something you know the value of (your profile name, for example). If Selenium-IDE can't find the element (or the name doesn't match), it'll let you know that the test has failed.

selenium not reading javascript alert in c#

i am using selenium ide for testing my .net website. i am testing login for the website by using selenium. i recorded the steps and as i am testing the code in visual studio the test case is failing. my test case is:
selenium.Open("//login.aspx");
selenium.Type("fldUsername", "abc");
selenium.Type("fldPassword", "abc");
selenium.Click("btnLogin");
bool log1 = selenium.IsPromptPresent();
Assert.IsNull(log1);
selenium.WaitForPageToLoad("80000");
here username and password are incorrect and is giving a alert. but using selenium it is not getting that alert. please someone help me out..
Probably should have been migrated to sqa.stackexchange.com, but, either way.
Is there any reason why you're creating log1. It would be much for efficient to do something like: Assert.isFalse(selenium.IsPromptPresent());
I don't use Selenium 1 much, however, after a quick test, this seems to work.
Assert.IsTrue(Regex.IsMatch(selenium.GetAlert(), "regex to match"));
As for the regex matching, if you're going to make sure that the prompt is there, you might as well make certain that it's the correct prompt.

Is any way to get captcha value and store it in a variable?

I am Using Selenium RC in C# My application has 3 Captha image in Different registration pages. i have a Huge script i will run it on night hours(when i am off). Hence i feel it will be better if i can capture the last displaying captcha image value and store it in to a variable so that i can input on the relevant field. Is it Possible ?
A Captcha cannot be automated that easily. That is why they were invented!!
Alas... You can use code hackers and Image Recognition patterns and scripts. It is called OCR. http://en.wikipedia.org/wiki/Optical_character_recognition
I will not write more about this as i wont encourage others for hacking ideas. But... First: Google is your friend. Second: In my testing environment we used a captcha with a static value. And then before it went live we removed set it again for the algorithm.
Gergely.
Have a hidden field (with a non-obvious name) that contains a strongly encrypted copy of the text used in the captcha then on your selenium test system decode it using the private key?
For testing purposes you will need to send the captcha value in a machine readable manner, by sending it as an additional field. You would then need to remove the field after the tests are done.
Make use of the 'input' tag with type 'hidden' in-order to handle Captcha.
JavascriptExecutor js = (JavascriptExecutor) driver;
//Set the captcha values using setAttribute
js.executeScript("document.getElementsByName('xxxx')[0].setAttribute('value', 'xxxx')");
driver.findElement(By.name("xxxx")).sendKeys("xxxx");