Implementing cross-browser with Selenium

Hi guys !!

I wrote a simple example of howย we can implementing cross browser code.

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class CrossBrowsers {

    public WebDriver Select(WebDriver driver) throws IOException, Exception {
        try {
            //Switch browsers
            switch (driver.getBrowser()) {
                case "firefox": {
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.setPreference("network.proxy.type", 0);
                    driver.setDriver(new FirefoxDriver(profile));
                    driver.getEnvironment();
                    break;
                }
                case "ie": {
                    DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
                    Proxy proxy = new Proxy();
                    proxy.setNoProxy(environment);
                    cap.setCapability(CapabilityType.PROXY, proxy);
                    cap.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); 
                    cap.setCapability("ignoreZoomSetting", true);
                    cap.setCapability("ignoreProtectedModeSettings" , true);
                    cap.setCapability("initialBrowserUrl", driver.getEnvironment());
                    File file = new File("drivers//IEDriverServer.exe");
                    System.setProperty("webdriver.ie.driver", file.getCanonicalPath());
                    driver.setDriver(new InternetExplorerDriver(cap));
                    driver.get(environment);                    
                    break;
                }
                case "chrome": {
                    DesiredCapabilities cap = DesiredCapabilities.chrome();
                    Proxy proxy = new Proxy();
                    proxy.setNoProxy(driver.getEnvironment());
                    cap.setCapability(CapabilityType.PROXY, proxy);
                    cap.setCapability("chrome.switches", Arrays.asList("--disable-web-security"));
                    cap.setCapability("chrome.switches", Arrays.asList("--safebrowsing-disable-download-protection"));
                    cap.setCapability("chrome.switches", Arrays.asList("--ignore-certificate-errors"));
                    File file = new File("drivers//chromedriver.exe");
                    System.setProperty("webdriver.chrome.driver", file.getCanonicalPath());
                    driver.setDriver(new ChromeDriver(cap));
                    driver.getEnvironment();
                    break;
                }
            }
        } catch (IOException ex) {
            System.print.out(ex);
        }
        return driver;
    }
}

If you have any question or suggestion, please just write below onย the comments.

Have a nice week everyone, Bye !!

JMeter Distributed Testing Step-by-step

Hi guys, I found this tutorial about Jmeter distributing testing in different PCS. This short tutorial explains how to use multiple systems to perform stress testing. Before we start, there are a couple of things to check.

  1. the firewalls on the systems are turned off.
  2. all the clients are on the same subnet.
  3. the server is in the same subnet, if 192.x.x.x or 10.x.x.x ip addresses are used. If the server doesn’t use 192 or 10 ip address, there shouldn’t be any problems.
  4. Make sure JMeter can access the server.
  5. Make sure you use the same version of JMeter on all the systems. Mixing versions may not work correctly.

Once you’ve made sure the systems are ready, it’s time to setup remote testing. The tutorial assumes you already have JMeter installed on all the systems. The way JMeter works is 1 master controller initiates the test on multiple slave systems.

1

Terminology
Before we dive into the step-by-step instructions, it’s a good idea to define the terms and make sure the definition is clear.
Master โ€“ the system running Jmeter GUI, which controls the test
Slave โ€“ the system running jmeter-server, which takes commands from the GUI and send requests to the target system(s)
Target โ€“ the webserver we plan to stress test
2
Step-by-Step

  1. On the slave systems, go to jmeter/bin directory and execute jmeter-server.bat (jmeter-server on unix). On windows, you should see a dos window appear with โ€œjre\[version]\bin\rmiregistry.exeโ€. If this doesn’t happen, it means either the environment settings are not right, or there are multiple JRE installed on the system. Note: [version] would be the jre version installed on the system.
  2. Open jmeter-server.bat in a text editor
  3. go to line 44 and find โ€œ:setCPโ€
  4. edit โ€œSTART rmiregistryโ€ to the full path. Example: โ€œSTART C:\<JAVA_HOME>\jre\bin\rmiregistryโ€
  5. On master system acting as the console, open windows explorer and go to jmeter/bin directory
  6. open jmeter.properties in a text editor
  7. edit the line โ€œremote_hosts=127.0.0.1โ€
  8. add the IP address. For example, if I have jmeter server running on 192.168.0.10, 11, 12, 13, and 14, the entry would like like this: remote_hosts=192.168.0.10,192.168.0.11,192.168.0.12,192.168.0.13,192.168.0.14
  9. Start jmeter.
  10. Open the test plan you want to use
3
Starting the Test
At this point, you are ready to start load testing. If you want to double check the slave systems are working, open jmeter.log in notepad. You should see the following in the log.
Jmeter.engine.Remote
JMeterEngineImpl:
Starting backing engine
If you do not see this message, it means jmeter-server did not start correctly. For tips on debugging the issue, go to the tips section. There are two ways to initiate the test: a single system and all systems.
Start a single clients
4
  1. click Run at the top
  2. select Remote start
  3. select the IP address

 

Start all clients

5
  1. click Run at the top
  2. select Remote start all or use CRTL-Z

 

Limitations

There are some basic limitations for distributed testing. Here’s the list of the known items in no specific order.

  1. RMI cannot communicate across subnets without a proxy; therefore neither can jmeter without a proxy.
  2. Since JMeter sends all the test results to the controlling console, it is easy to saturate the network IO. It is a good idea to use the simple data writer to save the results and view the file later with one of the graph listeners.
  3. Unless the server is a large multi processor system, in most cases

 

Tips

In some cases, the firewall may still be blocking RMI traffic.ย Symantec Anti Virus and Firewall.ย In some cases, Symantec firewall needs to be stopped from windows services.

  1. open control panel
  2. open administrative tools
  3. double click services
  4. Go to down to symantec anti virus, right click and select stop

Windows firewall

  1. open network connections
  2. select the network connection
  3. right click and select properties
  4. select advanced tab
  5. uncheck internet connection firewall

Linux

On Suse linux, ipchains is turned on by default. For instructions, please refer to the โ€œremote testingโ€ in the user manual.

On RedHat (or derivatives), iptables (netfilter) is turned on by default. Execute โ€œservice iptables stopโ€ to stop the Linux netfilter firewall.

 

Fonts:ย http://wiki.apache.org/jmeter/JMeterFAQ#How_to_do_remote_testing_the_.27proper_way.27.3F

http://jmeter.apache.org/usermanual/remote-test.html

http://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.pdf

Interview’s Logic Tests

Yes Guys !

I will write a post about this, because recently I made some logic tests that are VERY VERY easy, but because of my nervous I made some mistakes :/ Really, I have to stop to stay anxious about something… So, let’s go:

Tests Fibonnaci – JAVA:

packageย Tests;
publicย classย Mainย {
ย  ย ย staticย longย fibo(intย n)ย {
ย  ย  ย  ย ifย (nย <ย 2)ย {
ย  ย  ย  ย  ย  returnย n;
}ย elseย {
ย  ย  ย  ย  ย  returnย fibo(nย –ย 1)ย +ย fibo(nย –ย 2);
}
}
publicย staticย voidย main(String[]ย args)ย {ย //ย test
ย  ย  ย  ย ย forย (intย iย =ย 0;ย iย <ย 15;ย i++)ย {
System.out.print(Main.fibo(i)ย +ย “\t”);
}
}
}

Tests Reverse Stringย – JAVA:

packageย Tests;


publicย classย Mainย {

ย ย ย ย staticย Stringย converse()ย {
ย ย ย ย ย ย ย ย Stringย aย =ย "Thisย isย aย string...";
ย ย ย ย ย ย ย ย Stringย bย =ย "";

ย ย ย ย ย ย ย ย forย (intย iย =ย a.length()ย -ย 1;ย iย >=ย 0;ย i--)ย {
ย ย ย ย ย ย ย ย ย ย  ย bย =ย bย +ย a.charAt(i);
ย ย ย ย ย ย ย ย }
ย ย ย ย ย ย ย ย returnย b;
ย ย ย ย }

ย ย ย ย publicย staticย voidย main(String[]ย args)ย {ย //ย testย 
ย ย ย ย ย ย System.out.println(Main.converse());

    }
}

JMeter Setup on Mac

In summary, this initial setup will create a way for you to record all of the requests that get made when using your web-application. From here, you can save certain thread sets and run tests where multiple instances of these thread-sets are sent to your web app.

My plan is to use this to record what Selenium does, and then use that for load testing. If I use Selenium IDE to make the aforementioned Selenium routines, the redundancy is hilarious. But in all seriousness, I am really excited to pair the two of them together. I am a bit worried though about whether JMeter can keep up with Selenium…
What I am wondering is ‘What benefit is there to using JMeter over Fiddler?’… probably has to do with being able to integrate JUnit tests etc more easily… but I don’t know. Any comments?
First: Installation

  1. Downloadย JMeter. You may download the source code and build it yourself, or you may download the binaries. I just downloaded the binaries.
  2. While on the JMeter Download page, follow the instructions provided to verify the md5 (Mac OSX Snow Leopard Server does not come withย pgp,ย gpg, orย pgpk.)
    • In Terminal.app
      • md5ย jakarta-jmeter-2.5.1.zip
    • Click ‘md5’ next to the version of JMeter you downloaded. There will be a 20 character value shown, and it should match what you got in the the terminal. A quick way to check this is toย just useย โŒ˜+F in your browser and copy in your results from the terminal.ย 
  3. In your Finder, uncompressย jakarta-jmeter-2.5.1, and drill down into the directory calledย ‘bin’.
  4. Openย ApacheJMeter.jar
    • If you prefer the Terminal, use the following:
    • sh ./jakarta-jmeter-2.5.1/bin/jmeter.sh
Setup & Tuning-in to your web-browser
  1. Add (via right click) a Thread group to the Test Planย 1
  2. Add a Non Test Element > HTTP Proxy Server to the Workbenchย 2
  3. Open the HTTP Proxy Server Page and change the port if requiredย 3
  4. Set the Target Controller to Test Plan > Thread Group on the same pageย 4
  5. Configure your browser to use the Proxy Server (it’s localhost)ย 5
    1. Zac Spitzer recommends Firefox. This is probably the case because you can set up proxying internally toย Firefoxย without messing around with your system settings. If you try to go ‘Under the Hood’ in Chrome or into Safari’s ‘Change Settings…’ dialog, it will kick you right into your system preferences. Please note that if your workplace has a special proxy configuration already, or any other network settings that might interfere with setting this up, don’t fight it: submit a ticket to IT.ย 
      1. โŒ˜+,
      2. In ‘Advanced’, go to your connection settings and set up your localhost as a proxy server. You can assign different ports to different protocols.ย 
  6. Press Start at the bottom of the pageย 6

Now, JMeter will record all the HTTP requests your browser makes, so make sure you have closed all the other tabs you have open.ย 7

Don’t forget to reset your browser proxy settings!ย 8

You can delete any requests you don’t want from the list at any time.ย 9

Remember to read theย documentationย and be careful! Make sure you know what servers will be affected by your testing, and don’t jump to simple conclusions, 3-tier web apps are complex beasts.ย 10

What is cross-browser ? Why I have to perform it ?

Nowadays, weย have to test ourย application in a lot of browsers, but how ?

Cross-browser testing is choseย to guaranteeย that a website or web application worksย on different browsers and it involves compatibility check and testing of both client-side apps.

According to the statistics from W3Schools, Chrome is one of the most popular browsers these days with 54.1% market share followed by Firefox with 27.2% market share. On the other hand Internet explorer is at third place with 11.7% market share followed by Safari and Opera.

10268702_801134233233224_3463662876642180326_n

Maybe yourย website will look veryย different in all these browsers as each of the browsers will understand some code a littleย differently than the other one. For this reason, it is important to perform cross-browser testing to ensure your website runs on all the mainlyย browsers.

Reasons to test your website in other browser:

-Running browser specific testsย will spend more time.

-Customers never like to use the same browser.

-Mobile is in demand. Pay attention in mobile browsers.

-New technology is not supported by all browsers.

-You have to worry with the Security too.

-No one likes to maintain separate tests for each and every browser. (Of course, it is boring)

 

Browser Compatibility?

Check whether the application works the way it should across all the browsers, you should take a look at the following ingredients of a web application or website:

-HTML:

– CSS Styles & CSS Validations:

– Sessions & Cookies:

-JavaScript:

– Text Alignments & Page Layouts:

There are several other important areas of web applications to be considered for achieving 100% cross-browser compatibility such as:

-Font Sizes
-Mouse Hover
-SSL Certificates
-Upload File
-Export File
-Scroll Bar Appearance
-Flash Work
-Page Zoom In/Out
-Pop Ups
-Space between various HTML components, etc.

Functional Testing?

> There are 5 actively used versions of Internet Explorer, 8 versions of Firefox, 7 versions of Chrome, 3 versions of Safari and 3 versions of Opera. That makes a total of 26 versions of browsers on which to test your application.

> Even if you cut down to the main versions of each of the main browsers, you will have to repeat your web application testing at least 9 times.

> You need to test your application on multiple browser versions every time your application has a new release.

> You need to test your application on multiple browser versions every time the browser has a new release. Firefox releases a new version almost every 2 weeks.

> Manual testing on each browser version is time consuming, monotonous and prone to human errors.

When I know to stop a test?

Good morning/afternoon/evening for everyone !

Today I will talk about one thing that every tester must to know: How doย you know when you should stop testing?ย 

Everyone want to test everything, but we know that it is impossible. So, what we can do ? This is some guidelines that you can follow:

 

Set Time Guidelines

Provide aย block of time to perform the initial tests.ย Then reviewย the test results to determine next testing stepsย based upon the requirements and what you learned byย performing the initial tests. Continue this process untilย testing has been completed. By going through this process will help train you how to thinkย through the requirements, testing results, risks, identifyingย new testing ideas, and determining when to stopย testing.

Sometimes the initialย testing assignments are small enough to be completedย in one or two testing sessions. As the assignments becomeย larger it is beneficial to test in a continual feedbackย mode with a more experience tester.

 

Experience and Time

It is important to ask questions aboutย what you are testing because this will help you understand
how much time to spend testing.ย 

  • Based upon the requirements, I am planning onย performing the following tests;
  • Based upon what I learned during testing, I amย going to perform the following tests and I am not goingย to perform the following tests.ย 
  • As an overview of my testing I performed theย following tests and I did not test the following functionality.ย 

Diminishing Returns and Use of timeย 

Spendingย more time performing additional tests does not necessarilyย equate to added test value. There becomes a pointย where sufficient information and value has been gatheredย through testing and spending additional time testingย will not necessary produce more valuableย information. Instead, spending this additional testingย time on a different testing problem could be a better useย of time. When thinking about what is the best use of myย testing time, a tester needs to consider time constraintsย and what testing problems are still outstanding. Forย example you have to test problem A and B. You haveย already spent a lot of time testing problem A and haveย gathered a lot of valuable information. At this point, isย it better to spend more time performing additional testsย or should I move on to test problem B?

 

Risk Level of the Testing Issue

The higher the risk typically means you will spendย more time testing. However, that needs to be balancedย with the scope of the problem. For example, a high riskย change that touches many areas of the product willย require more testing time than a high risk change thatย touches a very small, isolated part of the product.

 

Bye guysย !ย 

Using Robotium to automate Test in Android

Hello guys !

Today I will write aboutย the benefits of using Robotium to automate the tests in apps of Android Cellphones. I hope that thisย list help you to decide what is the better tool to you use.

Robotium is an Android test automation framework that has full support for native and hybrid applications. Robotium makes it easy to write powerful and robust automatic black-box UI tests for Android applications. With the support of Robotium, test case developers can write function, system and user acceptance test scenarios, spanning multiple Android activities.

ย 

  • Test Android apps, both native and hybrid.
  • Requires minimal knowledge of the application under test.
  • The framework handles multiple Android activities automatically.
  • Minimal time needed to write solid test cases.
  • Readability of test cases is greatly improved, compared to standard instrumentation tests.
  • Test cases are more robust due to the run-time binding to UI components.
  • Fast test case execution.
  • Integrates smoothly with Maven, Gradle or Ant to run tests as part of continuous integration.

ย 

Bye ๐Ÿ™‚

Why use continuous integration

Integrate at least daily

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

By integrating regularly, you can detect errors quickly, and locate them more easily.

 

Solve problems quickly

Because youโ€™re integrating so frequently, there is significantly less back-tracking to discover where things went wrong, so you can spend more time building features.

Continuous Integration is cheap. Not continuously integrating is costly. If you donโ€™t follow a continuous approach, youโ€™ll have longer periods between integrations. This makes it exponentially more difficult to find and fix problems. Such integration problems can easily knock a project off-schedule, or cause it to fail altogether.

Continuous Integration brings multiple benefits to your organization:

  • Say goodbye to long and tense integrations
  • Increase visibility which enables greater communication
  • Catch issues fast and nip them in the bud
  • Spend less time debugging and more time adding features
  • Proceed in the confidence youโ€™re building on a solid foundation
  • Stop waiting to find out if your codeโ€™s going to work
  • Reduce integration problems allowing you to deliver software more rapidly

More than a process

Continuous Integration is backed by several important principles and practices.

The Practices

  • Maintain a single source repository
  • Automate the build
  • Make your build self-testing
  • Every commit should build on an integration machine
  • Keep the build fast
  • Test in a clone of the production environment
  • Make it easy for anyone to get the latest executable
  • Everyone can see whatโ€™s happening
  • Automate deployment

How to do it

  • Developers check out code into their private workspaces.
  • When done, the commit changes to the repository.
  • The CI server monitors the repository and checks out changes when they occur.
  • The CI server builds the system and runs unit and integration tests.
  • The CI server releases deployable artefacts for testing.
  • The CI server assigns a build label to the version of the code it just built.
  • The CI server informs the team of the successful build.
  • If the build or tests fail, the CI server alerts the team.
  • The team fix the issue at the earliest opportunity.
  • Continue to continually integrate and test throughout the project.

Team Responsibilities

  • Check in frequently
  • Donโ€™t check in broken code
  • Donโ€™t check in untested code
  • Donโ€™t check in when the build is broken
  • Donโ€™t go home after checking in until the system builds

Many teams develop rituals around these policies, meaning the teams effectively manage themselves, removing the need to enforce policies from on high.

Continuous Deployment

Continuous Deployment is closely related to Continuous Integration and refers to the release into production of software that passes the automated tests.

Essentially, โ€œit is the practice of releasing every good build to users,โ€ explains Jez Humble, author of Continuous Delivery.

By adopting both Continuous Integration and Continuous Deployment, you not only reduce risks and catch bugs quickly, but also move rapidly to working software.

With low-risk releases, you can quickly adapt to business requirements and user needs. This allows for greater collaboration between ops and delivery, fuelling real change in your organisation, and turning your release process into a business advantage.

 

Font:ย http://www.thoughtworks.com/continuous-integration